RequestDispatcher executing in wrong directory

Discussion in 'Java' started by DiscoStu, Jul 19, 2004.

  1. DiscoStu

    DiscoStu Guest

    Hello Everyone,

    I've got this servlet that I am writing, and inside of it, I want
    to pass control onto a JSP page. So, because I want to pass on the
    request/response objects into my JSP page, I decided to use the
    RequestDispatcher class. I call RequestDispatcher.forward(req, resp);
    and it sucessfully finds the JSP page but runs it in the servlet
    directory, rather then the directory the page is located in (root app
    directory).

    This causes the images not to show because the images are in the
    /images directory off the root. When the page uses relative URL's to
    reference its images its getting "servlet/images/imagename.gif"
    instead of executing off the root directory "/images/imagename.gif".

    How do I make the RequestDispatcher pass control off to the JSP page
    AND run the JSP in the directory it's located in and not the directory
    of the servlet that the RequestDispatcher class is being called from?

    Thanks everyone,

    GF
     
    DiscoStu, Jul 19, 2004
    #1
    1. Advertising

  2. DiscoStu

    Erwin Moller Guest

    DiscoStu wrote:

    > Hello Everyone,
    >
    > I've got this servlet that I am writing, and inside of it, I want
    > to pass control onto a JSP page. So, because I want to pass on the
    > request/response objects into my JSP page, I decided to use the
    > RequestDispatcher class. I call RequestDispatcher.forward(req, resp);
    > and it sucessfully finds the JSP page but runs it in the servlet
    > directory, rather then the directory the page is located in (root app
    > directory).
    >
    > This causes the images not to show because the images are in the
    > /images directory off the root. When the page uses relative URL's to
    > reference its images its getting "servlet/images/imagename.gif"
    > instead of executing off the root directory "/images/imagename.gif".
    >
    > How do I make the RequestDispatcher pass control off to the JSP page
    > AND run the JSP in the directory it's located in and not the directory
    > of the servlet that the RequestDispatcher class is being called from?
    >
    > Thanks everyone,
    >
    > GF


    Hi GF,

    > How do I make the RequestDispatcher pass control off to the JSP page
    > AND run the JSP in the directory it's located in and not the directory
    > of the servlet that the RequestDispatcher class is being called from?


    I don't know how. I didn't even knew that happened. :-/

    But maybe you could circumvent this behaviour by adding an extra attribute
    to the request, which points to the imagedirectory (relative or absolute).
    Set it to the correct value depending on the situation (plain JSP or the
    servlet-included situation).

    Alternatively: I alway have a 'global' variable containing the full URL to
    the imagedirectory, that is much easier to use.

    Good luck,
    Erwin Moller
     
    Erwin Moller, Jul 20, 2004
    #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. Paul Vincent Craven

    Multiple includes with RequestDispatcher

    Paul Vincent Craven, Aug 29, 2003, in forum: Java
    Replies:
    0
    Views:
    654
    Paul Vincent Craven
    Aug 29, 2003
  2. Will Handley
    Replies:
    1
    Views:
    584
    Nigel Wade
    Dec 10, 2003
  3. Ryan Stewart

    RequestDispatcher.include() behavior

    Ryan Stewart, May 20, 2004, in forum: Java
    Replies:
    0
    Views:
    489
    Ryan Stewart
    May 20, 2004
  4. John English
    Replies:
    6
    Views:
    3,926
    Andrea Desole
    Jul 19, 2005
  5. Replies:
    2
    Views:
    521
    Tor Iver Wilhelmsen
    Aug 18, 2005
Loading...

Share This Page