java - jsp跳转到servlet,出现404
巴扎黑
巴扎黑 2017-04-18 10:54:13
0
3
624

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

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

具体代码和配置如下:

form

xml

项目结构


哪里有错误呢?

巴扎黑
巴扎黑

reply all (3)
Peter_Zhu

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 usesaction值写做"/LoginServlet"是因为@WebServlet是Servlet3.0规范所支持的一种简化配置,他和你在 web.xml 中配置/LoginServletis 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

    伊谢尔伦

    Two questions:

      The annotation on
    1. LoginServletshould 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

      大家讲道理

      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

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!