在web.xml中映射servlet
xml文件位于我项目的WebContent/WEB-INF/web.xml
中。 我正在使用Eclipse并运行Tomcat(它不是通过Eclipse安装的。我更喜欢它是一个单独的安装)。
EmployeeManagement index.html index.htm index.jsp default.html default.htm default.jsp name Pramod Registration /EmployeeManagement/WebContent/Registration
当表单页面提交给servlet时它不起作用。 我每次都会收到404错误。 我一直遇到这个问题。 有人请帮帮我。
您缺少
标记,这对映射很重要。 所以使用以下:
EmployeeManagement index.html index.htm index.jsp default.html default.htm default.jsp name Pramod Registration com.yourPackageName.yourServletName Registration /EmployeeManagement/WebContent/Registration
你应该在你的表单上给出action
价值如下:
并且还注意到以下代码中的所有值都区分大小写:
Registration com.yourPackageName.yourServletName Registration /EmployeeManagement/WebContent/Registration
您的servlet名称Registration
在两个标记
和
应该相同,并且package
名称应该与servlet类所在的位置相同。
你没有将servlet名称映射到servlet类,它应该如下所示,
在
给出servlet的路径
Registration com.Registration Registration /EmployeeManagement/WebContent/Registration
检查您的表单操作。 是那条路
/EmployeeManagement/WebContent/Registration
要么
YOURAPPCONTEXT/EmployeeManagement/WebContent/Registration
要么
YOURAPPNAME/EmployeeManagement/WebContent/Registration
您已指定了servlet-mapping
并在servlet-name
使用了名称Registration
,而不在之前定义它。
在servlet映射中使用它之前,需要定义servlet
Registration [fully qualifyied name of your servlet]
您缺少另一部分来定义web.xml中的servlet
Registration package.path.to.RegistrationServlet
您忘记了配置的重要部分。 您应该在servlet-mapping
标记之前将其添加到web.xml
:
Registration com.name.of.your.servlet.class