FileDocCategorySizeDatePackage
DebugPost.javaAPI DocExample1759Thu May 15 10:32:40 BST 2003com.jspservletcookbook

DebugPost

public class DebugPost extends HttpServlet

Fields Summary
Constructors Summary
Methods Summary
public voiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)


    doPost(request,response);
public voiddoPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

	
	String file = request.getParameter("file");
	
    HttpClient httpClient = new HttpClient();
    PostMethod postMethod = new PostMethod(
        "http://localhost:8080/home/sendpdf");
    NameValuePair[] postData = {
          new NameValuePair("file", file),
        };
	//the 2.0 beta1 version has a PostMethod.setRequestBody(NameValuePair[])
	//method, as addParameters is deprecated
    postMethod.addParameters(postData);
	postMethod.addRequestHeader( new Header("Referer","http://localhost:8080/home/sendpdf?file="+file));
    httpClient.executeMethod(postMethod);
    //display the response to the POST method
    response.setContentType("text/html");
     java.io.PrintWriter out = response.getWriter();
     //A "200 OK" HTTP Status Code
    if (postMethod.getStatusCode() == HttpStatus.SC_OK) {
        out.println(postMethod.getResponseBodyAsString());
    } else {
        out.println("The POST action raised an error: " + postMethod.getStatusLine());
    }
	//release the connection used by the method
    postMethod.releaseConnection();
    out.close();