All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.Ostermiller.util.CGIParser.bte Maven / Gradle / Ivy

Go to download

Open source (GPL) Java utilities maintained by Stephen Ostermiller with help from many contributors.

The newest version!
<%bte.doc super="item.bte" %>
<%bte.tpl name=pageTitle%>CGI Query String Parser<%/bte.tpl%>
<%bte.tpl name=description%>Java libraries to to parse the query data supplied by HTTP GET or POST requests.<%/bte.tpl%>
<%bte.tpl name=keywords%>cgi parser, parse cgi, java cgi parser, common gateway interface parser<%/bte.tpl%>
<%bte.tpl name=topcontent%>Parses ampersand and equal sign delimited data from the query string of URLs.<%/bte.tpl%>
<%bte.tpl name=content%>


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.

<%/bte.tpl%> <%bte.tpl name=linkCGIParser%>CGI Query String Parser <%/bte.tpl%> <%/bte.doc%>




© 2015 - 2025 Weber Informatics LLC | Privacy Policy