aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Keep getting NullPointerException 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 » Sockets and Internet Protocols
Bookmark "Keep getting NullPointerException" Watch "Keep getting NullPointerException" New topic
Author

Keep getting NullPointerException

Ryan McClain
Ranch Hand

Joined: Nov 27, 2010
Posts: 79

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

Joined: Jan 10, 2002
Posts: 60046
    
  65

You might get better responses if you post a properly formatted stack trace.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Todd Buell
Greenhorn

Joined: May 31, 2005
Posts: 21
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

Joined: Nov 27, 2010
Posts: 79
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

Joined: Nov 27, 2010
Posts: 79
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

Joined: Nov 27, 2010
Posts: 79
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
 
subject: Keep getting NullPointerException
 
Similar Threads
using apache soap webservice in jboss
Apache axis
Data Alignment
Regarding struts with ajax
How to Implement POST Method in RESTFul web services using Jersey