Java web.xml中的servlet映射
xml文件位于我的项目的Java web.xml中的servlet映射,java,xml,eclipse,tomcat,servlets,Java,Xml,Eclipse,Tomcat,Servlets,xml文件位于我的项目的WebContent/WEB-INF/WEB.xml中。我正在使用Eclipse并运行Tomcat(它不是通过Eclipse安装的,我更喜欢单独安装) 员工管理 index.html index.htm index.jsp default.html default.htm default.jsp 名称 普拉莫德 登记处 /员工管理/网络内容/注册 当表单页面提交到servlet时,它不起作用。每次我都会遇到404错误。我遇到这个问题已经有一段时间了。有人请帮帮我。检查
WebContent/WEB-INF/WEB.xml
中。我正在使用Eclipse并运行Tomcat(它不是通过Eclipse安装的,我更喜欢单独安装)
员工管理
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp
名称
普拉莫德
登记处
/员工管理/网络内容/注册
当表单页面提交到servlet时,它不起作用。每次我都会遇到404错误。我遇到这个问题已经有一段时间了。有人请帮帮我。检查一下你的表格动作。
那条路在那里吗
/EmployeeManagement/WebContent/Registration
或
或
您还没有将servlet名称映射到servlet类,应该如下所示 在
中给出servlet的路径
<servlet>
<servlet-name>Registration</servlet-name>
<servlet-class>com.Registration<servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Registration</servlet-name>
<url-pattern>/EmployeeManagement/WebContent/Registration</url-pattern>
</servlet-mapping>
登记处
com.注册
登记处
/员工管理/网络内容/注册
您忘记了配置的一个重要部分。您应该在servlet映射之前将其添加到web.xml
标记中:
<servlet>
<servlet-name>Registration</servlet-name>
<servlet-class>com.name.of.your.servlet.class</servlet-class>
</servlet>
登记处
com.name.of.your.servlet.class
您指定了一个servlet映射
,并在servlet名称
中使用了名称注册
,之前没有定义它
在servlet映射中使用servlet之前,需要先定义servlet
<servlet>
<servlet-name>Registration</servlet-name>
<servlet-class>[fully qualifyied name of your servlet]</servlet-class>
</servlet>
登记处
[您的servlet的完全限定名称]
您缺少在web.xml中定义servlet的另一部分
<servlet>
<servlet-name>Registration</servlet-name>
<servlet-class>
package.path.to.RegistrationServlet
</servlet-class>
</servlet>
登记处
package.path.to.RegistrationServlet
您缺少对映射很重要的..
标记。因此,请使用以下命令:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>EmployeeManagement</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>name</param-name>
<param-value>Pramod</param-value>
</context-param>
<servlet>
<servlet-name>Registration</servlet-name>
<servlet-class>com.yourPackageName.yourServletName</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Registration</servlet-name>
<url-pattern>/EmployeeManagement/WebContent/Registration</url-pattern>
</servlet-mapping>
</web-app>
并记下以下代码中的所有值都区分大小写:
<servlet>
<servlet-name>Registration</servlet-name>
<servlet-class>com.yourPackageName.yourServletName</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Registration</servlet-name>
<url-pattern>/EmployeeManagement/WebContent/Registration</url-pattern>
</servlet-mapping>
登记处
com.yourPackageName.yourServletName
登记处
/员工管理/网络内容/注册
您的servlet名称注册
在标记..
和..
上应该相同,并且包
名称应该与您的servlet类所在的位置相同 发布您的表单操作
。我在您的web.xml中看不到Servlet标记。在哪里可以找到用于配置web.xml的Servlet名称和url模式
<servlet>
<servlet-name>Registration</servlet-name>
<servlet-class>
package.path.to.RegistrationServlet
</servlet-class>
</servlet>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>EmployeeManagement</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>name</param-name>
<param-value>Pramod</param-value>
</context-param>
<servlet>
<servlet-name>Registration</servlet-name>
<servlet-class>com.yourPackageName.yourServletName</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Registration</servlet-name>
<url-pattern>/EmployeeManagement/WebContent/Registration</url-pattern>
</servlet-mapping>
</web-app>
<form action="/EmployeeManagement/WebContent/Registration" method="post">
//Some code here
</form>
<servlet>
<servlet-name>Registration</servlet-name>
<servlet-class>com.yourPackageName.yourServletName</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Registration</servlet-name>
<url-pattern>/EmployeeManagement/WebContent/Registration</url-pattern>
</servlet-mapping>