当我尝试将一个动作从.jsp发送到serlvet时遇到了问题,当我按下链接时我会向servlet发送动作来处理它,但我总是遇到404代码错误。
课程分为如下:
Application
src
servlets
controllerServlet.java
WebContent
jsp
home.jsp
我在do get servlet方法上编写的代码是:
{
String action = request.getParameter("action");
switch (action) {
case "action1":
System.out.println("action 1");
break;
}
}
调用servlet的jsp中的代码是:
<li><a href="${pageContext.request.contextPath}/controllerServlet?action=action1">Page1</a></li>
web.xml文件是:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID"
version="3.1">
<display-name>Application</display-name>
<welcome-file-list>
<welcome-file>/jsp/home.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>controllerServlet</servlet-name>
<servlet-class>servlets.controllerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>controllerServlet</servlet-name>
<url-pattern>/controllerServlet</url-pattern>
</servlet-mapping>
</web-app>
但是我不明白为什么不工作,有人可以帮助我吗?