Home  >  Q&A  >  body text

java - jsp跳转到servlet,出现404

从网上下了一个小项目,其中一段代码不删除或者注释掉,服务器就会启动失败。如图所示:

注释之后,服务器能正常启动,但是jsp跳转失败。

具体代码和配置如下:

form

xml

项目结构


哪里有错误呢?

巴扎黑巴扎黑2718 days ago650

reply all(3)I'll reply

  • 天蓬老师

    天蓬老师2017-04-18 10:56:13

    Solve the problem first. The reason for your jsp jump failure is indeed as Ethan said. The url specified by the action in the form does not match the Servlet configured in web.xml. Just write it as "/ServletLearningChapter1_3/LoginServlet" and it will be fine

    In addition, in terms of expansion, the reason why the code you see on the Internet uses action 值写做 "/LoginServlet" 是因为 @WebServlet是Servlet3.0规范所支持的一种简化配置,他和你在 web.xml 中配置 <servlet><url-pattern>/LoginServlet</url-pattern></servlet> is a function.

    So when you comment out @webServlet, the value of url mapping should be based on web.xml.

    Finally, if you report an error, I hope you can type out the specific information next time. Otherwise, because we don’t have your environment information, we won’t be able to guess the specific problem.

    Well, that’s it, wish you well :D

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:56:13

    Two questions:

      The annotation on
    1. LoginServlet should be written in a certain framework. When the framework jar package is missing or the configuration is incorrect, the annotation will report an error and cause the startup to fail

    2. Configuration in the formaction中指定的url 与 web.xml中配置的Servlet 不匹配,按照web.xml, your action should be written like this

    <form action="/ServletLearningChapter1_3/LoginServlet" ...>

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-18 10:56:13

    The poster asked two questions and took a rough look at it. Visual inspection:
    Question 1: Are the definitions repeated?
    Question 2: The project path is missing?
    Not necessarily correct

    reply
    0
  • Cancelreply