错误实例:
tomcat启动错误:
1.Error running tomcat: Address localhost:1099 is already in use
这是tomcat的上一个线程没有关闭,从而导致了1099这个端口被占用
显然:如果把端口从8080改成80,我们就可以把http://localhost:8080/servlet_war_exploded/demo1
中的“8080”予以省略
servlet中的方法
@Override
public void init(ServletConfig servletConfig) throws ServletException {
System.out.println("一旦打开servlet就会触发他的打开方法");
}
@Override
public ServletConfig getServletConfig() {
/*
获得本servlet的配置
*/
return null;
}
@Override
public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
System.out.println("成功触发了servlet里的service方法");
}
@Override
public void destroy() {
System.out.println("stop tomcat时候,将会将这个servlet销毁");
}
}
在配置urlpartten:Servlet访问路径
- 一个Servlet可以定义多个访问路径 :
@WebServlet({"/d4","/dd4","/ddd4"})
- 路径定义规则:
1./xxx:
路径匹配
2./xxx/xxx:
多层路径,目录结构
3.*.do:
扩展名匹配
分析一个请求
POST /login.html HTTP/1.1 Host: localhost
请求行:请求方式 请求url 请求协议/版本 且这里的请求方式是post
接下来都是请求头的内容
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0
用户的版本信息
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
所接受的格式、语言、编码
Referer: http://localhost/login.html
告诉服务器,我是从哪里来,以防止盗链
Connection: keep-alive
我们两还连着吗?
Upgrade-Insecure-Requests: 1
请把http升级到https吧!不然就会报错啦
从这里开始,也就进入请求体的内容,这里才是用户真正能够传输的信息
username=zhangsan
用户信息等等....
网友评论