ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Software  >>  Advanced Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
how to get value in combo for updation?
 Question Submitted By :: Gaursh
I also faced this Question!!     Rank Answer Posted By  
 
  Re: how to get value in combo for updation?
Answer
# 1
1. DataServlet.java
import java.io.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class DataServlet extends HttpServlet{

  private ServletConfig config;
  //Setting JSP page
  String page="selectbox.jsp";

  public void init(ServletConfig config)
    throws ServletException{
     this.config=config;
     }
  public void doGet(HttpServletRequest request,
HttpServletResponse response) 
              throws ServletException, IOException {
    
    PrintWriter out = response.getWriter();
    //Establish connection to MySQL database
    String connectionURL =
"jdbc:mysql://192.168.10.59/messagepaging";
    Connection connection=null;
    ResultSet rs;
    response.setContentType("text/html");
    List dataList=new ArrayList(); 
      try {
       // Load the database driver
      Class.forName("com.mysql.jdbc.Driver");
      // Get a Connection to the database
      connection =
DriverManager.getConnection(connectionURL, "root", "root"); 
      //Select the data from the database
      String sql = "select message from message";
      Statement s = connection.createStatement();
      s.executeQuery (sql);
      rs = s.getResultSet();
      while (rs.next ()){
        //Add records into data list
        dataList.add(rs.getString("message"));
      }
      rs.close ();
      s.close ();
      }catch(Exception e){
      System.out.println("Exception is ;"+e);
      }
      request.setAttribute("data",dataList);
      //Disptching request
      RequestDispatcher dispatcher =
request.getRequestDispatcher(page);
      if (dispatcher != null){
        dispatcher.forward(request, response);
      } 
  }
}

JSP page "selectbox.jsp" is getting data in following way 
<% List data= (List) request.getAttribute("data");

Full code of JSP page is given as below:

2. selectbox.jsp
<%@ page language="java" import="java.util.*"%>
<html>
<head>
<script type="text/javascript">
function change()
{
var answer = document.getElementById('selc').value;
document.getElementById('textvalue').value=answer;
}
</script>
</head>
<body>
<h1>Use of Select Box in JSP</h1>
<table border="1" width="41%" height="53" cellspacing="0"
cellpadding="3" 
                                          bgcolor="#000080"
bordercolorlight="#FFFFFF">
<tr>
<td width="100%" height="18" colspan="2"><b>
<font color="#FF00FF">Select items from select
box</font></b></td>
</tr>
<tr>
<td width="17%" height="23">
<select name="ActionSelect" onChange="change()" id="selc" >
<%Iterator itr;%>
<% List data= (List)request.getAttribute("data");
for (itr=data.iterator(); itr.hasNext(); )
{
String value=(String)itr.next();
%>
<option value=<%=value%>><%=value%></option>
<%}%> 
</select>
</td>
<td width="83%" height="23"><input type="text" id="textvalue" />
</td>
</tr>
</table>
</body>
</html>

For servlet to run and execute we have to do servlet entry
into "web.xml" 
<?xml version="1.0" encoding="ISO-8859-1"?>

    <web-app>
     <display-name>Welcome to Tomcat</display-name>
     <description>Welcome to Tomcat</description>
     <servlet>
             <servlet-name>DataServlet</servlet-name>
              <servlet-class>DataServlet</servlet-class>
     </servlet>
     <servlet-mapping>
              <servlet-name>DataServlet</servlet-name>
              <url-pattern>/DataServlet</url-pattern>
     </servlet-mapping>
   </web-app>
 
Is This Answer Correct ?    3 Yes 1 No
Raj
 

 
 
 
Other Advanced Java Interview Questions
 
  Question Asked @ Answers
 
whats is mean by filter? SolutionNET1
What is a compilation unit?  1
What is the difference between Process and Threads?  10
diffrence between jsp and servelts.  6
what is DGC?  1
life cycle of an applet?  1
What is deadlock?  1
In connection pool,when 100 clients are requesting, in pool 100 objects is there, when another client is making request how it will work  3
What is the return type of interrupt method?  2
whats is mean by class.forName() whats the return type of class SolutionNET5
How to determine applet?s height and width?  1
Explain bind(), rebind(), unbind() and lookup() methods?  1
important features of java which differenciate it from c++  3
what is diff between Access modifier and specifier? L&T4
What is the difference between a stub and a skeleton? ABC3
does j2ee means advanced java  7
What is servlet preinitialization iFlex1
What is the use of Class.forName HCL13
what is stringBuffer and StringBuilder?  3
What is daemon thread?  1
 
For more Advanced Java Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com