servlets - How do i display database results in a JSP? -
i have control servlet forward request model servlet.the model servlet retrieves results database , forward display jsp.how display result set in jsp?do need write sql statement again in jsp?
no, use request attributes map pass data controlling servlet jsp page.
example. controller side:
void doget(httpservletrequest request, httpservletresponse response) { list<string> names = model.getnamesfromdb(); request.setattribute("names", names); // forward jsp follows ... }
example. jsp page:
<% list<string> names = (list<string>)request.getattribute("names"); // whatever want names %>
Comments
Post a Comment