Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

Question about Servlet's RequestDispatcher forward / file paths

Thread view: 
Harry - 22 Dec 2005 12:47 GMT
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..
Viator - 22 Dec 2005 14:40 GMT
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 :-)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.