Problem in Servlet redirect
String username=request.getParameter("username");
ResultSet rs=st.executeQuery("select * from regis where username='"+username+"'");
if(rs.next() ){
response.sendRedirect("register.jsp");
}
if username is existing the "register.jsp" page will redirect
but "register.jsp" page didnt hold anything which i have entered.
i want hold the values which i entered except username
so give me solution..
Re: Problem in Servlet redirect
One way to pass data from one page to another page you redirect to is to use URL parameters. See the URL for this page at javaprogrammingforums.com - it has a '?' followed by a p=39838 - that's the 'query part' of the URL. You read it in your code fragment with request.getParameter(...) - if you want another page to have access to the same data, you have to add that parameter to the URL in your redirect.
Re: Problem in Servlet redirect
- Use a RequestDispatcher object to wrap the destination JSP.
- Set parameters for the request.
- Forward processing to the destination page using RequestDispatcher.
Here is the sample code:
Code :
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("register.jsp");
request.setAttribute("username", "YourName");
dispatcher.forward(request, response);
immutable objects