Get queryString using post method

Posted on 2007-10-16
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
    LVL 92

    Expert Comment

    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


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

    Expert Comment

    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

    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Suggested Solutions

    Title # Comments Views Activity
    bigHeights  challenge 13 43
    bunnyEars challenge 6 45
    json format text only 4 46
    Eclipse Neon and jdk 1.8.0 11 37
    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…
    Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
    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 learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now