Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP and Servlet Question  RSS feed

 
Manish Jain
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi EveryBody,

I was asked in Interview that :

1.when should one use a servlet or JSP in a project?

2. what is diffrence between the calling requestdispatcher from request object and servletContext object?

can anyone please help me in this. I'll really appreciate it.

Manish Jain
SCJP1.4
 
Ritesh Agrawal
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Manish,

Lets look at your first question:

1.when should one use a servlet or JSP in a project?

I believe this is mostly a design design. JSP was introduced to separate presentation from business logic and to support dynamic web content. Usually, one should avoid too much of processing in JSPs and focus on content presentation although JSPs do support complex processing. Servlets are best suited for complex processing, and as filters and controllers (wrt MVC framework).

For the second question, you will readily find the answer if you go through the J2EE API Docs pages for ServletContext -> getRequestDispatcher(String path) method and ServletRequest->getRequestDispatcher(String path) Method.

I am pasting a few lines from both pages here for your ready reference..

2. what is difference between the calling requestdispatcher from request object and servletContext object?

From ServletContext Page:

The pathname must begin with a "/" and is interpreted as relative to the current context root.

From ServletRequest Page:

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.
[ August 03, 2005: Message edited by: Ritesh Agrawal ]
 
Manish Jain
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ritesh

You answered my both questions. I really appreciate and thankyou for these answers.

Thanks
Manish Jain
SCJP1.4
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!