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

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. moondaddy
    Replies:
    5
    Views:
    13,362
    =?Utf-8?B?d2hpZ2dpbnM=?=
    Sep 2, 2004
  2. Lionel
    Replies:
    1
    Views:
    2,557
    Bruce Barker
    Jul 29, 2005
  3. qazmlp
    Replies:
    1
    Views:
    857
    Jonathan Turkanis
    Feb 15, 2004
  4. Replies:
    2
    Views:
    876
  5. Replies:
    0
    Views:
    301
  6. Replies:
    2
    Views:
    777
    Chris Riesbeck
    Jun 9, 2008
  7. Replies:
    0
    Views:
    316
  8. Sal
    Replies:
    1
    Views:
    1,685
Loading...