RequestDispatcher executing in wrong directory

D

DiscoStu

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
 
E

Erwin Moller

DiscoStu said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top