It's not a secret anymore!
The moose likes Servlets and the fly likes request.getParam... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "request.getParam..." Watch "request.getParam..." New topic


ray bond
Ranch Hand

Joined: Oct 11, 2000
Posts: 111

hello there , I have an applet which post data to servlet at
"http://localhost/servlet/PostServlet?adclient=sun" url , then in servlet
I obtain "adclient" parameter , servlet code is like below ,

String clientparam = request.getParameter("adclient");
ServletInputStream servletinputstream = request.getInputStream();
DataInputStream datainputstream = new DataInputStream(servletinputstream);
System.out.println("line is null");
when I run applet they post data to servlet but servlet gives error "null pointer exception "
and also prints "line is null" which means datainputstream.readLine is null, if I take out code line ,
String clientparam = request.getParameter("adclient");
from servlet code then it works fine and without any error it gets all posted data
from applet and writes in the file , what could be the problem??
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
because POST parameters are passed in the body of the request, calling the method getParameter() automatically reads and parses the request body. If you need to read it yourself, you mustn't call getParameter().

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
I agree. Here's the link:
subject: request.getParam...
It's not a secret anymore!