File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

simple doubt reg HttpServletRequest

 
saikrishna cinux
Ranch Hand
Posts: 689
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
String protocol = req.getParameter();
}

I know that web container implements httpServletRquest

but in the above code i am not creating an object but i am accessing it's method
req.getParameter();

how can be it is possible
why it is not throwing nullpointerException

can any one please explain me whatz happening internally
while i run this code in the conainer
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by saikrishna cinux:
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
String protocol = req.getParameter();
}


Check the bold stuff above.

When request comes for any Servlets, container will (create and) passes HttpServletRequest and HttpServletResponse objects to doPost().

It's true that you are not creating objects – but container is.
[ June 03, 2006: Message edited by: Chetan Parekh ]
 
A Kumar
Ranch Hand
Posts: 980
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the request comes...the web container creates 2 objects for that request...

one object that implements HttpServletRequest ..
request object

one object that implements HttpServletResponse..
response object.

These objects(references) are passed to the service methods..

In normal servlets we write our output to this response

using PrintWriter object of the same..

Hope you got it..

Regards
 
saikrishna cinux
Ranch Hand
Posts: 689
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya i got it thanx to u both :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic