1.关于Servlet请求时405
在重写doGet和doPost方法时代码如下
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.doGet(req, resp);
PrintWriter writer = resp.getWriter();
writer.println("doGet~~~~");
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.doPost(req, resp);
PrintWriter writer = resp.getWriter();
writer.println("doPost~~~~");
}
建立服务器映射代码如下
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>com.makbkq.servlet.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
访问url为:http://localhost:8080/Servlet_01,结果正常
访问:http://localhost:8080/Servlet_01/hello时出现405
解决方法为删除super……语句
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
PrintWriter writer = resp.getWriter();
writer.println("doGet~~~~");
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
PrintWriter writer = resp.getWriter();
writer.println("doPost~~~~");
}
注:对此问题只找到了解决方法,对于原理尚且不知 ^ … ^,望大佬解释