• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Keep getting NullPointerException

 
Ranch Hand
Posts: 153
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might get better responses if you post a properly formatted stack trace.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 153
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 153
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 153
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic