Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Basic Servlet question  RSS feed

 
vijaya vinayagam
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) What is the difference between "request.getRequestDispatcher(path)" &
"ServletContext.getRequestDispatcher(path)" ???

2)
i have used <error-page> tag in my web.xml to map a exception to a particular html page.

why is it so i'am getting that page displayed only when i uncheck my "show friendly http error messages" in my browser tools -> advanced option. If it is enabled it gives me Http 500 error

( i'am having a JSP then request goes to a servlet and from there the exception is thrown)

browser : IE 6.0
server : Tomcat 5.0

thanks in advance
[ March 21, 2006: Message edited by: vijaya vinayagam ]
 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What is the difference between "request.getRequestDispatcher(path)" &
"ServletContext.getRequestDispatcher(path)" ???




request.getRequestDispatcher(path)-- takes the path that is relative to the current request
whereas ServletContext.getRequestDispatcher takes the path relative to the application context

say you have app name 'testApp'
you current request is 'jsp/page1.jsp'

if you use servlet context dispatcher == you will have path as '/testApp/jsp/page2.jsp'

if you use request ..you will have page as 'page2.jsp'
 
vijaya vinayagam
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi geetu lalchandani ,

Directory struc.
==================
vijProject
-- index.jsp, index1.html
-- WEB-INF
-- classes
-- firstservlet

from index.jsp the request goes to firstservlet and there i have the following

firstservlet.java
=====================================================
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, java.io.IOException
{
//getServletContext().getRequestDispatcher("/index1.html").forward(req,res);
req.getRequestDispatcher("/index1.html").forward(req,res);
}
=======================================================

both are working in the same way ... ( i had not mentioned the context name at any place )

thanks in advance
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!