#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    14
    Rep Power
    0

    Question URL updating from a servlet dispatcher


    Hi all!

    I got a jsp page (MeetingQuery.jsp) with a form whose action is:

    action="/Meeting/servlet/MeetingQueryProcess"


    This servlet processes the request and then sends user back to MeetingQuery.jsp:

    rd = request.getRequestDispatcher("/MeetingQuery.jsp");
    rd.forward(request, response);


    The problem is that in the URL we can see:

    http://localhost:8080/Meeting/servlet/MeetingQueryProcess


    Instead, I would like to see .../Meeting/MeetingQuery.jsp again. Is it possible and if yes, how to do that?
    Thanks for your answers!
    ::Tiago
  2. #2
  3. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    You're going to have to force the browser to make a new request to the other page. You can either send back some javascript, meta refresh, or (at least with php) a location header. This will generate a new request object, though, so you won't be able to access anything from the original.
    You might give the user a "query successful" mesage (like this board does when you post a reply), then redirect them to the jsp.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    Boston, MA
    Posts
    30
    Rep Power
    57
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    Boston, MA
    Posts
    30
    Rep Power
    57

    Solution


    The solution to this problem is not hard, but it required some research.

    I didn't get any help from anyone and I couldn't find a tutorial, but I got some idea to put the path after the servlet and use a servlet mapping in web.xml.

    My idea was that I could then parse the location from the servlet to get the real page I wanted to go to. This would allow me to have doGet and doPost handle the page almost identically while using a RequestDispatcher.

    It turns out that the servlet API already has such feature, so I was partially reinventing the wheel. The method is getPathInfo of HttpServletRequest.

    I made a quick tutorial on it and put it on my website.

    http://dhtmlkitchen.com/java/servlet/bookmarkable/

    You'll be surprised how easy it is.


    Garrett
  8. #5
  9. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    You can also use response.sendRedirect() in place of request.getRequestDispatcher().forward(). The disadvantage of this of course is that you can't send the request and response objects on, but you can still use sessions and the query string.

IMN logo majestic logo threadwatch logo seochat tools logo