Request
(1) 原理


(2)继承结构

(3).方法的介绍

(4).创建
Servlet 快速创建


@WebServlet(urlPatterns = "/ServletDemo1")
public class ServletDemo1 extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//请求头
Enumeration<String> headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String name = headerNames.nextElement();
String header = request.getHeader(name);
System.out.println(name+ "---" + header);
}
//获取头
String header = request.getHeader("user-agent");
String reforer = request.getHeader("reforer");
System.out.println(reforer);
//为什么使用 contains
if (header.contains("chrome")){
System.out.println("谷歌来了");
}
//请求行
String method = request.getMethod();
System.out.println(method);
System.out.println(request.getContextPath());
//比较URL 和 URI 的区别
System.out.println(request.getRequestURI());
System.out.println(request.getRequestURL());
//GET
///MyWeb_war
///MyWeb_war/ServletDemo1
//http://localhost:8080/MyWeb_war/ServletDemo1
中文乱码问题

请求访问


共享数据

登录案例

(BeanUtils的使用)

网友评论