I want to send multiple data values that has been retrieved from database to another servlet or jsp.
Here is my code
PreparedStatement st= conn.prepareStatement("select name from users where uname=? and pword=?");
st.setString(1, uname);
st.setString(2, pword);
ResultSet rs= st.executeQuery();
if(rs.next())
{
if(uname.equals(uname) && pword.equals(pword))
{
request.setAttribute("name", rs.getString("name"));
request.setAttribute("uname", uname);
HttpSession ss= request.getSession();
ss.setAttribute("name",rs.getString("name"));
ss.setAttribute("uname",rs.getString("uname"));
response.sendRedirect("Dash.jsp");
}
}
I want to send both name as well as uname(username) to another jsp file called "Dash.jsp". But it is not working. if i comment any one of the following code :
ss.setAttribute("name",rs.getString("name"));
ss.setAttribute("uname",uname));
then the servlet is passing the data to Dash.jsp
I also tried to use RequestDispatcher by applying the following code :
request.setAttribute("name", rs.getString("name");
request.setAttribute("uname",uname);
String destination = "Dash.jsp";
RequestDispatcher rd =
getServletContext().getRequestDispatcher(destination);
rd.forward(request, response);
Even if i give destination="/WEB-INF/pages/Dash.jsp" . then also it is not going to Dash.jsp page.
Can anybody please tell me how to send multiple values or data in this case name,uname from one servlet or jsp to another.