%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=content%>
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.
The servlet implementation that I am using does 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.
[Download /w Source | Version History | Browse Source | Documentation]