getting int variable value from another servlet -
i have question regarding calling int number servlet. lets have 2 servlets. servlet 1 gives me variable number database. im servlet 2 have function can print out variable. how can that?
the servlets interact return value database called allay_hours_sum. number, fx 35.5. in servlet 2 have function can call number. have not made servlet 2 yet.
this code retrieve number mysql database:
string sql = "select *, (day_hours + (day_minutes / 60)) allday_hours workdata "; //where startdate='?' , enddate='?' preparedstatement pst = connection.preparestatement(sql); resultset rs = pst.executequery(sql); float allday_hours_sum = 0; while (rs.next()){ allday_hours_sum += rs.getfloat("allday_hours"); } res.setcontenttype("text/html;charset=utf-8"); res.getwriter().print(allday_hours_sum);
best regards mads
you need set variable value in request
request.setattribute("allay_hours_sum",allay_hours_sum);
pass request servlet using requestdispatcher
requestdispatcher rd=request.getrequestdispatcher("yoursecondservlet"); rd.forward(request,response);
then can value in second servlet
integer allay_hours_sum=(integer)request.getattribute("allay_hours_sum");
Comments
Post a Comment