【Java开源代码栏目提醒】:网学会员,鉴于大家对Java开源代码十分关注,论文会员在此为大家搜集整理了“ViewRequestServlet.java”一文,供大家参考学习!
package com.learnweblogic.examples.ch2;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class ViewRequestServlet extends HttpServlet {
/*
* Create a method to handle the GET request for your servlet:
*/
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
handleRequest(req, res);
}
/*
* Create a method to handle the POST request for your servlet:
*/
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
handleRequest(req, res);
}
/*
* Provide a common handler for GET and POST
*/
public void handleRequest(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
// set the response Content-Type
res.setContentType("text/html");
// obtain a PrintWriter stream to write to.
PrintWriter out = res.getWriter();
// print out our text
out.println("<html>");
out.println("<head><title>ViewRequest Servlet</title></head>");
out.println("<body>");
out.println("<h1>Requested URL:</h1>");
out.println("<pre>");
out.println(req.getRequestURL().toString());
out.println("</pre>");
out.println("<h1>HttpServletRequest information:</h1><pre>");
// Returns the Request Method. For Example, PUT or GET.
out.println("<br>Request method " + req.getMethod());
// Returns Request Scheme. Likely "HTTP 1.1"
out.println("<br>Request scheme " + req.getScheme());
// The protocol type for the request. Likely HTTP.
out.println("<br>Request protocol " + req.getProtocol());
// A subset of the complete URL.
out.println("<br>Request URL " + req.getRequestURI());
// Info on the path to the servlet.
out.println("<br>Servlet path " + req.getServletPath());
out.println("<br>Path info " + req.getPathInfo());
out.println("<br>Path translated " + req.getPathTranslated());
out.println("<br>Query string " + req.getQueryString());
// Info on the Request Content
out.println("<br>Content length " + req.getContentLength());
out.println("<br>Content type " + req.getContentType());
// Local Server Details.
out.println("<br>Server name " + req.getServerName());
out.println("<br>Server port " + req.getServerPort());
// Remote Host and User Information
out.println("<br>Remote user " + req.getRemoteUser());
out.println("<br>Remote address " + req.getRemoteAddr());
out.println("<br>Remote host " + req.getRemoteHost());
out.println("</body></html>");
} // handleRequest
} // ViewRequestServlet
上一篇:
ViewProductServlet.java
下一篇:
试论建设企业信息化提升企业竞争力