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

Keep getting NullPointerException

 
Ryan McClain
Ranch Hand
Posts: 145
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello

I am trying to manually do a behind-the-scenes HTTP POST through telnet on 127.0.0.1 port 8080 with TomCat 6 server running.
The problem is that it will not work.

I have the following servlet (BeerSelect.java):

and the following model Java class:

Everything works fine when I use http://localhost:8080/Beer-v1/form.html in my browser and hit 'submit'.
The resulting servlet-processed page is shown to me with the correct output:

Beer Selection Advice

try: Jail Pale Ale
try: Gout Scout

However, when I try to do a manual HTTP POST in telnet the following error is returned after 2x hit enter:

I am simply trying to pass a parameter to get the page to work.
Is it possible to do a POST in telnet and upon refreshing the page in the browser to get the post-resulted page?
Perhaps that cannot be done because when you refresh the page a simple GET would be done... hm.

What am I not understanding or doing wrong?

Thanks,

--
Ryan
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might get better responses if you post a properly formatted stack trace.
 
Todd Buell
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm going to wager a guess that the request parameter isn't getting set when you're sending the telnet request. Make sure the parameter is getting passed in. The following will compile and look just fine but will cause an NPE when there is not a request parameter called "foo".

 
Ryan McClain
Ranch Hand
Posts: 145
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I know that Todd.

Question is, how do I pass it in through telnet?
I am reading in the 'Head First Servlets & JSP' book that the parameters are simply beneath the headers in the request.
And so I wrote such in notepad:

I copied this literally from notepad and pasted it (right click, paste) into the cmd window.
I do not know why the parameter is not passed in. Perhaps something to do with the Enter not being literal. I do not know.

Meanwhile I will try to find out.
 
Ryan McClain
Ranch Hand
Posts: 145
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finally figured it out.

It appears I had to specify 'Content-Length' and 'Content-Type'.
The nail was 'Content-Length', because if you enter the wrong length, the server will ignore your commands.
So this is the working, fixed HTTP POST request:

As you can see the Content-Length is 10, because "color=dark" are ten characters.

Problem solved.

Regards,

--
Ryan
 
Ryan McClain
Ranch Hand
Posts: 145
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This topic should be marked as resolved, so that other fellow internet users can look it up on Google and find it.

--
Ryan
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic