• Post Reply Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher question

 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have read lots of threads that try to clarify the paths associated with a requestdispatcher.
but the damn thing isnt yet clear. i have probelms even while running some sample applications of my own, which usee the requestdispatcher

i have a servlet that says

RequestDispatcher rd = getServletContext().getRequestDispatcher("/result.jsp");

but when i run my app, i see a blank page, or in other words, contents from the result.jsp arent displyed on the browser
where should i place the result.jsp ?? Please mention propery the exact directory structure

Now if i make the servlet to say -

1) RequestDispatcher rd = request.getRequestDispatcher("/jsp/result.jsp");

where do i keep the "jsp" folder ? should i keep it as
myApp/WEB-INF/jsp/reult.jsp OR
myApp/jsp/result.jsp ??

2) RequestDispatcher rd = request.getRequestDispatcher("result.jsp");
again the same question-- where should i keep the result.jsp ?

3) RequestDispatcher rd = request.getRequestDispatcher("/result.jsp");
where should i place the result.jsp ??


4)RequestDispatcher rd = getServletContext().getRequestDispatcher("/jsp/result.jsp");

where do i keep the "jsp" folder ? should i keep it as

myApp/WEB-INF/jsp/reult.jsp OR
myApp/jsp/result.jsp ??

When you reply to my query.please dont bluff the typical lines from the spec- "relative to the context root" or "relative to current request

i want a dirctory structure for all the POSSIBLE paths that we can use in getRequestDispatcher(String path)
i would be grateful if you give a explanation lik - "if the path is "...../..../....jsp" then place the jsp in "..../.../..." where .... is directory name.

the whole thing is f****ing me a lot, and i want to get a solid understaning of it in my mind.

"EVEN IF I AM TAKING CARE OF THE DIRECTORY STRUCTURE AND THE PATHS, WHAT COULB B THE REASON THAT I M NOT
GETTING A BLANK PAGE AS TEH OUTPUT??"

please help out
niranjan

[BSouther: Removed cursing from the subject line]
[ June 20, 2006: Message edited by: Ben Souther ]
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Java Ranch!

This particular forum is for questions about the SCJA certification test. I will move this post to the Servlets forum where the experts on this topic visit often. For the future, please find the forum that more closely fits the topic of your question.

Thank you,

Layne
 
Jignesh Gohel
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the basic the directory structure for a web-application is


Now u should place all ur jsp pages either in the folder u created for storing the jsp pages or keep them in the directory urAppName (ie at the same level where u have created WEB-INF).

Now when passing the path as argument to the requestDispatcher give the path where ur jsp pages are stored that is if u r not creating any extra folder for storing jsp pages as mentioned above then mention the path as

getRequestDispatcher("/urJSPPageName.jsp") and if creating the folder then getRequestDispatcher("/thatfolderName/urJSPPageName.jsp").
[ June 20, 2006: Message edited by: Jignesh Gohel ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you look at the API?
Particularly, did you look at the methods that return an instance of requestDispatcher?

java.lang.String)" target="_blank" rel="nofollow">ServletContext.getRequestDispatcher
The pathname must begin with a "/" and is interpreted as relative to the current context root. Use getContext to obtain a RequestDispatcher for resources in foreign contexts. This method returns null if the ServletContext cannot return a RequestDispatcher.


java.lang.String)" target="_blank" rel="nofollow">HttpServletRequest.getRequestDispatcher
The pathname specified may be relative, although it cannot extend outside the current servlet context. If the path begins with a "/" it is interpreted as relative to the current context root. This method returns null if the servlet container cannot return a RequestDispatcher.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!