Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Forward output to Jsp from servlet  RSS feed

 
saahil sinha
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,
I need help with request dispatcher used in servlet to forward request to jsp.I have stored my file display.jsp in tomcat 4.1\webapps\ROOT directory now how do specify the path in request dipatcher do i specify it as /display.jsp or c:\program files\apache group\tomcat 4.1\webapps\root\display.jsp.

Please dont tell me im suppsoe to give the path relative to root context coz i cant seem to understand wht tht means in tomcat i have placed the file under ROOT directory and my servlet is under
ROOT/WEB-INF/CLASSES/FINANCE directory
so can anyone please tell me the path tht i am suppose to give to my display.jsp in request dispatcher object.
I am unable to understand but whtever path i give it just doesnt seem to forward to the jsp page.So pls tell me what path i should give maybe wht path i gave was wrong.
Plsssss help.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm afraid the path has to be relative...
If you're feeling confused about the "two roots", ../ROOT/ and ../ROOT/WEB-INF/classes, don't worry. It's actually quite straight forward once you get the hang of it.
Two things:
- ROOT is the web application's root directory and it's contents act just like with regular web servers' root directories.
- ROOT/WEB-INF is a special directory of which contents are only accessible by the web container.
You can refer to the web application's JSP pages either with relative or absolute paths BUT "absolute" here does not mean "absolute" as in filesystem but "absolute relative to the webapp root directory".
Examples of absolute paths:
- file "ROOT/display.jsp" => path "/display.jsp"
- file "ROOT/subdir/page.jsp" => path "/subdir/page.jsp"
Examples of relative paths (notice missing slashes in the beginning of path strings!):
- file "ROOT/display.jsp" can point to file "ROOT/sibling.jsp" with relative path "sibling.jsp"
- file "ROOT/display.jsp" can point to file "ROOT/subdir/child.jsp" with relative path "subdir/sibling.jsp"
- file "ROOT/child.jsp" can point to file "ROOT/display.jsp" with relative path "../display.jsp"
The servlets that go under WEB-INF/classes cannot be accessed directly with a URL. You first need to map a URL to each servlet in WEB-INF/web.xml. For example, you can map servlet com.example.MyServlet to the URL pattern "/servlet/MyServlet". Then the servlet can be referred to by JSP pages and other servlets with "/servlet/MyServlet". You can also use wildcards in the mapping. For example, with mapping com.example.MyServlet <-> "/*" you would say to the web container that all requests should be handled by MyServlet.
Hope that clears it up a bit.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!