File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Problem with request.getParameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem with request.getParameter" Watch "Problem with request.getParameter" New topic

Problem with request.getParameter

parampreet sethi

Joined: Aug 03, 2009
Posts: 27

Hi Everyone,

I am facing this weird issue in my Servlet class.

If I print the value of request.getQueryString() function, it shows the value as "action=getall" but when I do request.getParameter("action"), this returns me a null value. I am not able to figure out why its happening.

Any pointers to the solution will be helpful.


Brij Garg
Ranch Hand

Joined: Apr 29, 2008
Posts: 234
It would be a great help if you can post the code.
parampreet sethi

Joined: Aug 03, 2009
Posts: 27

My code snippet is as follows:

I have tried printing request.getParameterMap(), it returns an empty string.

The only change I have done in my app is changing the Java URL rewriting (using tuckey urlrewrite.jar file) to Apache mod_rewrite.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63870

Please UseCodeTags.

[Asking smart questions] [About Bear] [Books by Bear]
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

The only change I have done in my app is changing the Java URL rewriting (using tuckey urlrewrite.jar file) to Apache mod_rewrite.

The first thing I would do is try it without mod_rewrite. Just hit the servlet container directly.
If the problem doesn't exists when hitting it directly, then you know that that mod_rewrite is not configured properly.
I'm guessing this is the case.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
parampreet sethi

Joined: Aug 03, 2009
Posts: 27

Hi Ben,

thanks for the reply. I have done the same thing now . I have reverted back mod_rewrite change to use tuckey url rewrite again. And it seems to be working fine now.

Will have to debug the issue with mod_rewrite configuration. Its very strange since I have just compiled the Apache with mod_rewrite module enabled and added the same URL regex which were given in url_rewrite.xml file for Tuckey in the mod_rewrite.conf.

Here is step by step mod_rewrite configuration I have done:

1. Installed apache with mod_rewrite enabled. And configured mod_jk connector to connect to Tomcat.
2. Created new file mod_rewrite.conf inside <APACHE_HOME>/conf directory with below mentioned content

3. Added entry inside conf/httpd.conf file below line

4. Started both Tomcat and Apache server.

The weird part is this problem is coming very randomly and not for the same URLs also. I tried printing the values of request.getParameterMap() which returns empty map, request.getParameterNames() returns empty enumeration even though request.getQueryString() returns "action=getall".

Please let me know in case I have missed something in configuration.
parampreet sethi

Joined: Aug 03, 2009
Posts: 27

To solve this issue, I put a hot fix in my app. Since I was always getting action parameter in request.getQueryString(), I put the following code:

When I restarted my App, I noticed that none of the parameters which were sent using the POST method were present in the request object. Looks like new request object is getting created some how on the path from Apache to Tomcat and losing all the values which were sent initially.

Still, the URLs failing randomly is unexplainable.
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 650
I'm not sure I understand what you're doing, but I just want to make sure you realize that the query string is not the same as the request parameters. When the form action is POST, request parameters will (generally) not be in the query string.

I'll stop here in case I misunderstood what you meant.
parampreet sethi

Joined: Aug 03, 2009
Posts: 27

Yes you are right that request.getQueryString() method will return only GET request parameters.

Since initially I thought the problem is with just one parameter which was added through rewrite rule:

Step 1: My app gets a POST request from the calling client (which sends another parameters in POST request) in the form of
Step 2: Apache mod_rewrite parse the above URL and send the newly created URL /TestServlet?action=get to the Tomcat.
Step 3. When the request reaches tomcat, when I print request.getQueryString() method it returns "action=get", but when I do request.getParameter("action") it returns a null value.

Just for a work around, since I was getting the value of action in QueryString always, I thought of parsing it and get the value of action.

But it did not solve my problem, since other parameters which were sent in POST request are also coming as NULL.
I agree. Here's the link:
subject: Problem with request.getParameter
It's not a secret anymore!