为了账号安全,请及时绑定邮箱和手机立即绑定

form提交路径正确也是404 找不到servlet

form提交路径正确也是404 找不到servlet

自小生来神气壮 2016-08-29 10:18:49
这是提交的jsp页<form action="<%=request.getContextPath() %>/servlet/Loginservlet" method="post"> 账号<input type="text" name="username"/><br /> 密码<input type="password" name="password"/><br /> <input type="submit" value="登录"/> </form>然后这是doPostprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String accountname = request.getParameter("username"); String accountpassword = request.getParameter("password"); if(accountname.equals("admin") && accountpassword.equals("admin")) { request.getRequestDispatcher(request.getContextPath()+"/success.jsp"); (request.getSession()).setAttribute("name", accountname); }else { response.sendRedirect(request.getContextPath()+"/login.jsp"); } }我用的   @WebServlet("/LoginServlet")   自动注解 就没有直接配置web.xml如果把注解注释了 手动配置web。xml就会tomcat都启动不了
查看完整描述

4 回答

?
yanrun

TA贡献317条经验 获得超240个赞

@WebServlet注解需要servlet3.0以上才能支持,看一下你的jar包对不对,还有就是web.xml里的web-app的version也要改成3.0才可以

查看完整回答
反对 回复 2016-08-29
  • 自小生来神气壮
    自小生来神气壮
    都对 web-app也是3.0
  • yanrun
    yanrun
    那感觉是你的web.xml有问题
  • 自小生来神气壮
    自小生来神气壮
    <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>loginfilter</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app> 自动生成的 用的eclipse 求指导
点击展开后面9
?
大咪

TA贡献785条经验 获得超332个赞

用注解方式应该是可以的呀,但是你的这个注解中写错了吧,应该是@WebServlet(name = "LoginServlet",urlPatterns="/LoginServlet"),就是你@WebServlet(),光标放进括号中,按alt+/应该有自动提示的,并且你用注解方式的话,name,url这两个应该是必须要写的。正确望采纳,谢谢


查看完整回答
反对 回复 2016-08-29
  • 自小生来神气壮
    自小生来神气壮
    复制过去试了一下 还是一样的404 而且开始注解是创建servlet自动生成的应该不会出错
  • 大咪
    大咪
    哦哦,不好意思啊我的那个URL写错了- -少东西。。。你在复制一下试试@WebServlet(name = "LoginServlet",urlPatterns={"/LoginServlet"})
  • 大咪
    大咪
    看下这回行不行,还是不行的话那我也不清楚了- -
点击展开后面11
  • 4 回答
  • 0 关注
  • 6123 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信