
If i want to get dynamic value in html textbox or in jsp,then how can I get the value,how the value will be transfered from servlet page to the html textbox,and values will be of string type or integer type or date type.........Thanx in advance.....Kindly help me...........

1)Servlet.java:
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Servlet extends HttpServlet{
protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException{
form.EmpBean p = new form.EmpBean();
List list=new ArrayList();
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from employee");
while(rs.next()){
list.add(rs.getString("name"));
list.add(rs.getString("address"));
list.add(rs.getString("contactNo"));
list.add(rs.getString("email"));
}
}
catch(Exception e){}
req.setAttribute("data", list);
RequestDispatcher rd = req.getRequestDispatcher("/jsp/data.jsp");
rd.forward(req, res);
}
}
2)data.jsp:
<%@page language="java" import="java.util.*" %>
<html>
<body>
<table border="1" width="303">
<tr>
<td width="119"><b>Name</b></td>
<td width="168"><b>Address</b></td>
<td width="119"><b>Contact no</b></td>
<td width="168"><b>Email</b></td>
</tr>
<% Iterator itr;%>
<% List data=(List)request.getAttribute("data");
for(itr=data.iterator(); itr.hasNext(); ){
%>
<tr>
<td width="119"><input type="text" value="<%=itr.next()%>"></td>
<td width="168"><input type="text" value="<%=itr.next()%>"></td>
<td width="168"><input type="text" value="<%=itr.next()%>"></td>
<td width="168"><input type="text" value="<%=itr.next()%>"></td>
</tr>
<%}%>
</table>
</body>
</html>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.