[英]JSP Servelet 404 Exception Tomcat
I have a java servelet which is also mapped in web.xml file but when i run it it raises 404 error. 我有一个Java servelet,它也映射到web.xml文件中,但是当我运行它时,会引发404错误。 Here is my source Code My Form with action is shown below
这是我的源代码“我的表单”及其操作如下所示
<form name="productsForm" method="post" action="/Checkout">
Here is my web.xml file 这是我的web.xml文件
<?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>AP Assignment 5</display-name>
<servlet>
<description>Called to process any forms on the website</description>
<display-name>Form Processing Servlet</display-name>
<servlet-name>Checkout</servlet-name>
<servlet-class>Servlets.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Checkout</servlet-name>
<url-pattern>/Checkout</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
Here is my project hierarchy with my servelet code 这是我的服务代码与我的项目层次结构
you have 2 mistakes in your web.xml 您的web.xml中有2个错误
.class
.class
.
) not slash( /
) .
)而不是斜杠( /
) so change 所以改变
<servlet-class>Servlets/MyServlet.class</servlet-class>
to 至
<servlet-class>Servlets.MyServlet</servlet-class>
Remove .class
from <servlet-class>
that is invalid here. 从
<servlet-class>
删除在此无效的.class
。
It should be 它应该是
<servlet-class>Servlets.MyServlet</servlet-class>
instead of 代替
<servlet-class>Servlets/MyServlet.class</servlet-class>
--EDIT-- - 编辑 -
try with appending Context Path if you are using it in JSP or append context path directly if using it in HTML. 如果在JSP中使用上下文路径 ,请尝试附加上下文路径;如果在HTML中使用它,则尝试直接附加上下文路径。
<form name="productsForm" method="post"
action="<%=request.getContextPath() %>/Checkout">
instead of 代替
<form name="productsForm" method="post" action="/Checkout">
Please have a look at similar issue form action=“/sampleServlet” giving me exception . 请看看类似的问题, 形式为action =“ / sampleServlet”给我例外 。
according to my point of view there are no errors on web.xml as well as servelet page. 根据我的观点,web.xml以及servelet页面上没有错误。 web.xml should be
web.xml应该是
<servlet>
<servlet-name>ServeletName</servlet-name>
<servlet-class>Package.ServeletName</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServeletName</servlet-name>
<url-pattern>/ServeletName</url-pattern>
</servlet-mapping>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.