Question about Servlet's RequestDispatcher forward / file paths

Discussion in 'Java' started by Harry, Dec 22, 2005.

  1. Harry

    Harry Guest

    I've written a servlet that takes an XML request and responds with a
    forward to a JSP.
    This will essentially produce an HTML output for the response.
    My question is how I can preserve the context file paths for the HTML
    (as all the images referenced from the HTML appear as broken).

    e.g.
    // After processing the XML request, program forwards to a JSP as
    follows.
    RequestDispatcher rd =
    request.getRequestDispatcher("/displayCustDetail.do");
    rd.forward(request, response);

    The above action will generate an HTML output (generated by the JSP) as
    the response.
    The HTML output is correct when I output to a browser window. Only
    problem is the paths in the HTML do not have any reference to the
    "http://host name" and the images all appear as broken..

    e.g. currently showing as <img src="/appName/images/welcome.gif">

    How do I preserve the correct context paths?

    Harry..
    Harry, Dec 22, 2005
    #1
    1. Advertising

  2. Harry

    Viator Guest

    You are giving an absolute path by appending a "/" in front. If you
    want an absolute path see getConetxtPath() method or HttpRequest
    object. If both the request and response are in same context ypu can
    use relative path instead.

    Any way for a side note, the .do extension is a convension of Struts
    and there you do not use RequestDispatcher generally with Struts.


    Amit :)
    Viator, Dec 22, 2005
    #2
    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. Will Handley
    Replies:
    1
    Views:
    580
    Nigel Wade
    Dec 10, 2003
  2. circuit_breaker
    Replies:
    2
    Views:
    1,996
    Jack Jia
    Apr 4, 2004
  3. Jan van Mansum
    Replies:
    0
    Views:
    464
    Jan van Mansum
    Jul 23, 2006
  4. harryos
    Replies:
    2
    Views:
    1,701
  5. Replies:
    0
    Views:
    564
Loading...

Share This Page