Now, in some phones, the request sent by clicking the Login link contains value "application/x-www-form-urlencoded" for the request header "content-type" and in some other phones, the request sent by clicking the Login link contains value "application/x-www-form-urlencoded; charset=106" for header "content-type". And in the later case, the jsp / servlet, receiving the request gets no post parameters (request.getParameter("mobileNo") returns null) - that's probably bcoz Servlet specification says like that ... (am I right?) ... This is the main problem - since no post parameters are available to the called jsp/servlet, no further processing is being done.

So, I was wondering if there is a way through which I can ensure that every request sent contains value "application/x-www-form-urlencoded" for header "content-type"?? If there is one, I think it should solve my problem ...

No, the parameters will get parsed if they are in the request body, no matter what the content-type value says. The problem must lie elsewhere. If this was my problem I would dump all the request headers and the InputStream to see what is actually being sent to the servlet. Bill

Ankit Doshi
Ranch Hand

Joined: Dec 04, 2002
Posts: 222

posted Sep 21, 2004 23:31:00

0

Here is the dump of the request headers (in case the request.getParameter returns null) :

And here is the dump of the content read from input stream (entire stringbuffer content) :

[test2.jsp]: Read data from input stream ==>mobileNo=6625016887<==

btw, the reason that I interpreted the content-type thing as stated in my question is because of the following :

Servlet Specification 2.3 - SRV.4.1.1 "When Parameters Are Available" - section states four different conditions that must be met before post form data will be populated to the parameter set, third of which is "The content type is application/x-www-form-urlencoded"

Please correct me if I have interpreted this incorrectly.

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 13004

5

posted Sep 22, 2004 07:00:00

0

Wow, you are right - I was mistaken. I even found the code in Tomcat 4.1.28 where the check is made. This is in the parseParameters method of HttpRequestBase.java which gets called if getParameters is called.

where contentType has been pulled out of the headers and cleaned up. If you want to force the value of content-type, a filter would be the way to do it. You can create a custom extension of HttpServletRequestWrapper that has special handling of the getHeader method. Bill

Ankit Doshi
Ranch Hand

Joined: Dec 04, 2002
Posts: 222

posted Sep 23, 2004 01:42:00

0

I am getting a feeling that, if I use a filter to force content type as you said, it would be sort of patch work. I even don't know why servlet specification says that post parameters should not be populated in case the content-type is NOT "application/x-www-form-urlencoded". There must be some reason behind this ...

I haven't worked much with filters, but, if somehow I find a way to do this through filters, then effectively we would force tomcat to parse parameters even if the request originated from the ultimate client has content-type other than "application/x-www-form-urlencoded". Would this be (direct or indirect) violation of servlet spec?

Also can you suggest me some more details for this filtering approach? I know how to write simple filters like set character encoding ... haven't worked with wrappers and all ... or if you can point me to some examples which can be helpful to me ...

Thanks

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 13004

5

posted Sep 23, 2004 07:04:00

0

This is a nice review article on Filters. It is true that some sort of filter to force the content-type would be a kludge - but what you would be fixing is the way the phone request headers are treated. After looking at the servlet code, I don't see why the header

What I have done wrong in the above code? I am not sure about how this request wrapper class would be used by tomcat ...

With the above code, If I do request.getHeader("content-type") from my JSP page, then it returns me value "application/x-www-form-urlencoded", BUT, the post parameters returned from request.getParameter still returns null, which means, tomcat is not getting the above value of content-type when it is trying to populate request headers.

Also, I have placed a System.out call in the getHeader of my requestwrapper class, which is not being printed when tomcat is populating parameters, which means my wrapper's method is not being called.

Ankit Doshi
Ranch Hand

Joined: Dec 04, 2002
Posts: 222

posted Sep 28, 2004 05:24:00

0

I got the URL (that response.encodeURL generates) printed in the system output :

This time, I tried with the following various cases of filter-mapping in web.xml, but no luck yet ...

Option 1:

Option 2:

Ankit Doshi
Ranch Hand

Joined: Dec 04, 2002
Posts: 222

posted Sep 28, 2004 07:06:00

0

any clues??

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 13004

5

posted Sep 28, 2004 07:20:00

0

I just realized that you have not said exactly what URL the following code generates:

also you may have the invoker servlet turned on. If that url includes "/servlet/" then processing by the invoker may be messing things up. Try creating a context separate from the Tomcat /examples. Bill