欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

HttpServletRequest

程序员文章站 2022-03-10 13:00:55
...

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class RequestLineServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html; charset=GB2312");
PrintWriter out = response.getWriter();

out.println("getMethod:" + request.getMethod() + "<br>");
// 返回位于主机和端口之后、参数部分之前的那部分内容
out.println("getRequestURI:" + request.getRequestURI() + "<br>");
// 返回参数部分,无参数返回null
out.println("getQueryString:" + request.getQueryString() + "<br>");
// 返回协议名和版本号
out.println("getProtocol:" + request.getProtocol() + "<br>");
// 返回Web应用程序的路径(虚拟目录),这个路径以“/”开头
out.println("getContextPath:" + request.getContextPath() + "<br>");
// 返回servlet映射的路径(web.xml的url-pattern属性)
out.println("getServletPath:" + request.getServletPath() + "<br>");
}
}

参考文献:[url]http://my.oschina.net/u/1171518/blog/221452[/url]
相关标签: HttpServletRequest