Get queryString using post method

Posted on 2007-10-16
Medium Priority
Last Modified: 2010-05-18
If form method is kept as get, my problem at java servlet path is over, as i am able to get querystring. But due to some architecture problem, it is not feasible to make form method as get. So, how can I retrieve the same querystring using post method.
Question by:rajneetbhatia
  • 3
  • 2
LVL 92

Expert Comment

ID: 20084917
you can access the passed parameters in the same way regardless of whether it is GET or POST
why do u need the query string exactly?
LVL 92

Expert Comment

ID: 20084962

String value = request.getParameter("paramname");
LVL 92

Expert Comment

ID: 20084987
If you need the query string then build it yourself

String queryString = "a="+request.getParameter("a")+"&b="+request.getParameter("b");  // add others as needed

LVL 86

Accepted Solution

CEHJ earned 500 total points
ID: 20087817
You can avoid hardcoding and save typing by doing

StringBuilder sb = new StringBuilder("?");
for(Enumeration e = req.getParameterNames();e.hasMoreElements();) {
      String param = e.nextElement().toString();
String queryString = sb.toString().substring(0, sb.length() - 1);
LVL 86

Expert Comment

ID: 20091264

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses
Course of the Month14 days, 6 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question