Using redirect instead of forward

Discussion in 'Java' started by teser3@hotmail.com, Jun 9, 2008.

  1. Guest

    --------------------------------------------------------------------------------
    In Tomcat 4.1.27 servlet I am using RequestDispatcher type to forward
    a message and get it in JSP. How can I do the same using redirect
    instead?

    Here is what I have -

    Servlet:
    request.setAttribute("MyMessage", "Hello");RequestDispatcher
    requestDispatcher = request.getRequestDispatcher("/
    toPage.jsp");requestDispatcher.forward(request, response);

    toPage.jsp
    out.println(request.getAttribute("MyMessage"));



    Now using redirect would this be the best way?
    String myMessage =
    "Hello";session.setAttribute("myMessage",myMessage);response.sendRedirect("/
    toPage.jsp");

    toPage.jsp
    out.println(session.getAttribute("MyMessage"));
     
    , Jun 9, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. qazmlp
    Replies:
    1
    Views:
    619
    Jonathan Turkanis
    Feb 15, 2004
  2. Replies:
    0
    Views:
    244
  3. Replies:
    2
    Views:
    714
    Chris Riesbeck
    Jun 9, 2008
  4. Replies:
    0
    Views:
    247
  5. Sal
    Replies:
    1
    Views:
    842
Loading...

Share This Page