How can I tidy up this servlet parameter check code?
In my opinion you could use the Regex to solve this

protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    resp.setContentType(CONTENT_TYPE);
    PrintWriter out = resp.getWriter();
    int maximumResults = defaultMaxResults;

    // you could create pathPattern as a Class field
    Pattern pathPattern = Pattern.compile("http://www.hostname.com/servletname/([^/]+)(/(\\d+))?$");

    Matcher m = pathPattern.matcher(req.getPathInfo());
    if(m.find()) {
         String param1 = m.group(1);
         String param2 = m.group(2); // NOTE param2 may be null
         // TODO your business here
         return;
    } else {
         // TODO throw your exception here
    }

}


You can change the pathPattern to meet your need. Hope this help. Feel free to response.