The moose likes Servlets and the fly likes setting http Header using urlconnection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "setting http Header using urlconnection" Watch "setting http Header using urlconnection" New topic

setting http Header using urlconnection

Maggie Taylor

Joined: Feb 14, 2006
Posts: 10
I have a servlet that recives http header information from a client program.

Now I have observed that when I assign a string value (including empty string ) in conn.addRequestProperty(), then the program works good. But, when I assign a null as any header value, then even the next header value displays a null even if I have assigned a value to it.

Here's a snippet from the client program:

A snippet from the servlet:

Can anybody help me in figuring out why this is happening ? I'm working on JDeveloper / Tomcat server.

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12759
What exactly are you trying to accomplish by setting the property to null?
I would guess that you have broken the request header mechanism and an incomplete set of headers is sent - can you look at the actual headers transmitted with TCPMON or similar mechanism?
Maggie Taylor

Joined: Feb 14, 2006
Posts: 10
Originally posted by William Brogden:
What exactly are you trying to accomplish by setting the property to null?

Thanks for replying Bill. I am testing the application for all different values - which include all these:
1)assigning a string as value
2)assinging an empty String as value
3)assinging a null as value

and the program is breaking down for the 3rd condition - showing null for next header value as well.

Rashid Mayes
Ranch Hand

Joined: Jan 11, 2006
Posts: 160
Hello, It may be better not to set the header at all if you want the value to be null. Try something similar to:

Rashid Mayes
http://www.hostj2me.com/ - http://www.worlddeveloper.org/
jQuery in Action, 2nd edition
subject: setting http Header using urlconnection
Similar Threads
error for first web application : The requested resource (/Beer-v1/SelectBeer.do) is not available.
How to store a particular data into project file
Setting the HTTP Request Headers
whilst fooling around with SessionId and cookies...
javax. servlet.Servlet Exception: Initialization failed, Unable to get DB connection