java - return both count and list from DAO -
i'm writing web app need return total number of rows servlet jsp.
i'm unable know how can send count
attribute jsp along userbeans
.
below code.
servlet
package org.servlet; import org.dao.*; import org.bean.userbean; import java.io.ioexception; import java.util.list; import javax.servlet.servletexception; import javax.servlet.annotation.webservlet; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; @webservlet("/getdata") public class getdata extends httpservlet { private static final long serialversionuid = 1l; public getdata() { super(); } getdatadao getdatadao = null; protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { // set content type try { getdatadao = new getdatadao(); list<userbean> userbeans = getdatadao.list(); int count = getdatadao.getthecount(); request.setattribute("userbeans", userbeans); request.setattribute("count", count); request.getrequestdispatcher("getcasedata.jsp").forward(request, response); } catch (exception e) { // todo auto-generated catch block e.printstacktrace(); } } }
jsp:
<div class="status"> <span class="totaltime"></span> </div> <input type="submit" value="get case" name="getcase" id="getcase" disabled="disabled" /> <table> <tr> <td>case number</td> <td><input id="casenumber" name="casenumber" type="text" value="${userbeans[0].getcasenumber()}" /></td> <td>case owner</td> <td><input id="caseowner" name="caseowner" type="text" value="${userbeans[0].getcaseowner()}" /></td> </tr>
i want count
value in <span class="totaltime"></span>
. please let me know how can this.
i know can done below.
<span class="totaltime"><%=request.getattribute("count")%></span>
but don't want include java code in jsp, in standard mvc way.
please let me know how can done.
thanks
Comments
Post a Comment