Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

JSP and Servlet Question

 
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
 
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
 
I'm all tasted up for a BLT! This tiny ad wants a monte cristo!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic