This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

request.getParam...

 
ray bond
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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);
if(datainputstream.readLine==null)
{
System.out.println("line is null");
}
while((strclient=datainputstream.readLine())!=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??
thanks.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic