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 had for forward -

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


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

    --------------------------------------------------------------------
    Here is what I am attempting for redirect but not sure if this is
    correct or efficient?
    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:
    594
    Jonathan Turkanis
    Feb 15, 2004
  2. Replies:
    0
    Views:
    252
  3. Replies:
    0
    Views:
    231
  4. Replies:
    2
    Views:
    695
    Chris Riesbeck
    Jun 9, 2008
  5. Sal
    Replies:
    1
    Views:
    402
Loading...

Share This Page