在idea中学习javaweb中的servlet遇到的问题(仅记录学习中遇到的问题)

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~~~~");
    }

注:对此问题只找到了解决方法,对于原理尚且不知 ^ … ^,望大佬解释

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值