Follow Our FB Page << >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...

how to get value in combo for updation?

how to get value in combo for updation?..

Answer / raj

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{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {

PrintWriter out = response.getWriter();
//Establish connection to MySQL database
String connectionURL =
Connection connection=null;
ResultSet rs;
List dataList=new ArrayList();
try {
// Load the database 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 ( ()){
//Add records into data list
rs.close ();
s.close ();
}catch(Exception e){
System.out.println("Exception is ;"+e);
//Disptching request
RequestDispatcher dispatcher =
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.*"%>
<script type="text/javascript">
function change()
var answer = document.getElementById('selc').value;
<h1>Use of Select Box in JSP</h1>
<table border="1" width="41%" height="53" cellspacing="0"
<td width="100%" height="18" colspan="2"><b>
<font color="#FF00FF">Select items from select
<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);
<option value=<%=value%>><%=value%></option>
<td width="83%" height="23"><input type="text" id="textvalue" />

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

<display-name>Welcome to Tomcat</display-name>
<description>Welcome to Tomcat</description>

Is This Answer Correct ?    6 Yes 2 No

Post New Answer

More Advanced Java Interview Questions

Write a program to show synchronization?

0 Answers  

When is the best time to validate input?

0 Answers  

what is activation monitor and what is its job?

1 Answers  

What is ioc concept & explain it?

0 Answers  

Will the general public have access to the infobus apis?

0 Answers  

What is ripple effect?

0 Answers  

What is JTS?

0 Answers  

Differences between applications and applets?

3 Answers  

whats is stored procedure,joins

1 Answers   Photon,

what is handle?

0 Answers  

what is Bootstrap loader program?

0 Answers   Rossell Techsys,

What is the diffrence between a local-tx-datasource and a xa-datasource? Can you use transactions in both?

0 Answers