Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Problem in Servlet redirect

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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..


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default 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.

  3. #3
    Member
    Join Date
    Aug 2011
    Posts
    48
    My Mood
    Fine
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default 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:

    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("register.jsp");
    request.setAttribute("username", "YourName");
     
    dispatcher.forward(request, response);

    immutable objects
    Last edited by ha.minh.nam; December 4th, 2011 at 07:31 PM.

Similar Threads

  1. Need help with a simple jsp and servlet problem
    By javacoder_APAC in forum Java Servlet
    Replies: 4
    Last Post: March 23rd, 2011, 08:32 AM
  2. [SOLVED] Redirect command prompt output to log file.
    By goldest in forum File I/O & Other I/O Streams
    Replies: 9
    Last Post: November 24th, 2010, 05:26 AM
  3. Authentication problem in a servlet
    By Asido in forum Java Servlet
    Replies: 3
    Last Post: September 17th, 2010, 05:57 AM
  4. Problem with the servlet and jdbc
    By manjukdvg in forum Java Servlet
    Replies: 3
    Last Post: September 8th, 2010, 08:44 AM