從網(wǎng)上下了一個小項(xiàng)目,其中一段代碼不刪除或者注釋掉,服務(wù)器就會啟動失敗。如圖所示:
注釋之后,服務(wù)器能正常啟動,但是jsp跳轉(zhuǎn)失敗。
具體代碼和配置如下:
form
xml
項(xiàng)目結(jié)構(gòu)
哪里有錯誤呢?
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"
是因?yàn)?@WebServlet
是Servlet3.0規(guī)范所支持的一種簡化配置,他和你在 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
Two questions:
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
Configuration in the formaction
中指定的url 與 web.xml
中配置的Servlet
不匹配,按照web.xml
, your action should be written like this
<form action="/ServletLearningChapter1_3/LoginServlet" ...>
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