File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes simple doubt reg HttpServletRequest Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "simple doubt reg HttpServletRequest " Watch "simple doubt reg HttpServletRequest " New topic
Author

simple doubt reg HttpServletRequest

saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
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


A = HARDWORK B = LUCK/FATE If C=(A+B) then C=SUCCESSFUL IN LIFE else C=FAILURE IN LIFE
SCJP 1.4
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
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 ]

My blood is tested +ve for Java.
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 978
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

Joined: Apr 16, 2005
Posts: 689
ya i got it thanx to u both :-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: simple doubt reg HttpServletRequest
 
Similar Threads
Servlets&JDBC-CallableStatement
Why I cannot do ftp in servlet
how to communicate Applet to Servet
Why the code works in GET and not in POST?
null pointer exception