Ostermillerutil Java Utilities CGI Query String Parser - com.Ostermiller.util Java Utilities

Parses ampersand and equal sign delimited data from the query string of URLs.

Example

public void doGet (HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException { 
    doPostGet(
        request, 
        response, 
        new CGIParser(
            request.getQueryString(),
            // Use the same character set
            // used in response.setContentType
            "UTF-8"
        )
    );
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    doPostGet(
        request, 
        response, 
        new CGIParser(
            request.getReader(),
            // Use the same character set
            // used in response.setContentType
            "UTF-8"
        )
    );
}

private void doPostGet(HttpServletRequest request, HttpServletResponse response, CGIParser params)
    throws ServletException, IOException {
    ...
}
If using this class in servlets, you would request the parameters from the params object rather than from the request.

Some servlet implementations do not parse the CGI name value pairs correctly for either POST or GET requests when there is a large amount of query data. Luckily, you can parse the query data yourself. I have written a class to do so. Its methods for retrieving the name value pairs are identical to the three methods in the http request of the servlet. The class can be created from the string of the GET request or the stream of the POST request.


License

OstermillerUtil Java Utilities Copyright (c) 2001-2020 by Stephen Ostermiller and other contributors

The OstermillerUtils library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

License FAQs - Why GPL? How about the LGPL or something else?