HTTP状态405-此URL不支持HTTP方法GET


关于HTTP状态405-此URL不支持HTTP方法GET解决方案

public class LoginServlet extends HttpServlet {
	@Override
	    //1.初始化登入次数
	public void init() throws ServletException {
	    //2.获取全局管理者
		ServletContext context=getServletContext();
		 
		//3.初始化次数
		context.setAttribute("count", 0);
	}
	
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		//0.设置编码
		 resp.setContentType("text/html;charset=utf-8");
		//1.接受用户名和密码
		String username= req.getParameter("username");
		String password= req.getParameter("password");
		 
		//2.调用userservice里的login(username , password)返回值:User
		User user = null;
		try {
			//携带表单数据的name,pwd去数据库查询;
			user = new userserice().login(username , password);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//3.判断user是否为空
		if(user==null){
			//3.1若为空写"用户名和密码不匹配'
			resp.getWriter().print("用户名和密码不匹配,3秒之后跳转主页");
			//定时跳转
			resp.setHeader("refresh", "3;url=/Servlet-login/login.html");
		}else{
			//3.2若不为空写"xxx:欢迎回来”
			resp.getWriter().print(user.getUsername()+"欢迎回来");
			
			//4.获取全局管理者
			ServletContext context = this. getServletContext( ) ;
			//5.获取总次数
			Integer cishu = (Integer) context . getAttribute("count");
			//6.将次数+1
			cishu++;
			//7.将次数再次放入域对像中
			context . setAttribute("count",cishu);

		}
		//super.doGet(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	
		
	}


}

​​​​​​​

结束语:

一把泪,解决的办法:一是要把post提交的方法改为get;

改完你就认为问题就解决了?,nonono,真是当头一棒啊;

去度娘找了下终于找解决办法;

竟然只要去掉//super.doGet(req, resp);就可以了但具体原因不明;

解决注明处:用户对问题“此URL不支持HTTP状态405-HTTP方法GET”的回答 - 问答 - 云+社区 - 腾讯云

  • 18
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值