Java Web编写一个servlet,测试获取请求行相关信息的方法

package cn.itcast.chapter04.request;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class RequestLineServlet
 */
@WebServlet("/RequestLineServlet")
public class RequestLineServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RequestLineServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out=response.getWriter();
		//获取请求行的相关信息
		out.println("getMethod:"+request.getMethod()+"
"
); out.println("getRequestURL:"+request.getRequestURL()+"
"
); out.println("getQueryString:"+request.getQueryString()+"
"
); out.println("getProtocol:"+request.getProtocol()+"
"
); out.println("getContextPath:"+request.getContextPath()+"
"
); out.println("getPathInfo:"+request.getPathInfo()+"
"
); out.println("getPathTranslated:"+request.getPathTranslated()+"
"
); out.println("getServletPath:"+request.getServletPath()+"
"
); out.println("getRemoteAddr:"+request.getRemoteAddr()+"
"
); out.println("getRemoteHost:"+request.getRemoteHost()+"
"
); out.println("getRemotePort:"+request.getRemotePort()+"
"
); out.println("getLocalAddr:"+request.getLocalAddr()+"
"
); out.println("getLocalName:"+request.getLocalName()+"
"
); out.println("getLocalPort:"+request.getLocalPort()+"
"
); out.println("getServerPort:"+request.getServerPort()+"
"
); out.println("getServerName:"+request.getServerName()+"
"
); out.println("getScheme:"+request.getScheme()+"
"
); out.println("getRequestURI:"+request.getRequestURI()+"
"
); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request,response); } }

Java Web编写一个servlet,测试获取请求行相关信息的方法_第1张图片

你可能感兴趣的:(Java,Web,java,前端,开发语言)