jsp - How to get Data from Mysql to be in Value of text in servlet -


how data mysql in value of text in servlet

i try code not working

 while(rs.next()){ out.println("<form action=\"userpage\" method=\"post\">" + " <input type=\"text\" name=\"id_customer\" value=\"<%=rs.getstring(1)%>\">" + "</form>"); } 

you should have create separate view (.jsp) instead of producing dynamic content of html in servlet.

first of create list<t> represent database result in servlet or model class , assign list object request (request scope) via request.setattribute() method.

public class customer { private int id; ..... public void setid(int id) { } public int getid() { return id;} } 

in servlet,

list<customer> listofcustomer=new arraylist<customer>(); //code populate listofcustomer database request.setattribute("list",listofcustomer); request.getrequestdispatcher("/show.jsp").forward(request,response); 

the view show.jsp should be:

<c:foreach var="customer" items="${listofcustomer}"> <form method='post' action='servlet_url'> <input type="text" name="id_customer" value="${customer.id}" /> </form> </c:foreach> 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -