Pass parameters from servlet to jsp using the url


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Pass parameters from servlet to jsp using the url

  1. #1
    Join Date
    Sep 2003
    Posts
    2

    Pass parameters from servlet to jsp using the url

    Hi i have a servlet that passes control to a jsp this way:

    String url = "/test.jsp?code=1&msg=" + URLEncoder.encode("foo message");
    System.out.println(url);
    RequestDispatcher rd = request.getRequestDispatcher(url);
    rd.forward(request,response);

    Doing that way test.jsp doesn't receive msg parameter, and in explorer's navigation bar this url can be seen:

    http://myserver/test.jsp?code=1&msg=foo+message

    it seems that the RequestDispatcher turns & into & and the url in the standard output (System.out) is

    /test.jsp?code=1&msg=foo+message

    How can i avoid this behaviour?

    Thnx.

  2. #2
    Join Date
    Mar 2003
    Posts
    86

    sendRedirect

    Try:
    response.sendRedirect(url).

    JavaDoc

    Sharbov.

  3. #3
    Join Date
    Sep 2003
    Posts
    2
    Don't want to do so.
    It implies that the query has to go back client and return to the server. I don't want't to do so

    I want forward to work. I know other workarround is to put the parameters in the request scope
    by using request.setAttribute, and reading them using request.getAttribute in test.jsp, but i have a large number of jsp pages and i don't want to do this chage.

    Any other hint?

    Thnx.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center