Java 如何在web.xml中映射jsp类?
我试图将编译好的jsp类映射到web.xml文件中,该类位于tomcat服务器文件夹的org.apache.jsp文件夹中,这样我就不想发布jsp代码了 我正在使用下面的代码,但是得到了HTTP状态404-。我反复检查,路径是正确的,并且类文件也在该路径中可用。我不知道为什么会出现此错误Java 如何在web.xml中映射jsp类?,java,xml,jsp,Java,Xml,Jsp,我试图将编译好的jsp类映射到web.xml文件中,该类位于tomcat服务器文件夹的org.apache.jsp文件夹中,这样我就不想发布jsp代码了 我正在使用下面的代码,但是得到了HTTP状态404-。我反复检查,路径是正确的,并且类文件也在该路径中可用。我不知道为什么会出现此错误 <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>org.apache.jsp.index_jsp</servlet-name>
<servlet-class>org.apache.jsp.index_jsp</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>org.apache.jsp.index_jsp</servlet-name>
<url-pattern>/index.jsp</url-pattern>
</servlet-mapping>
</web-app>
org.apache.jsp.index\u jsp
org.apache.jsp.index\u jsp
org.apache.jsp.index\u jsp
/index.jsp
有人能帮我解决这个问题吗?您必须使用jsp file标记在web.xml中进行jsp映射
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>org.apache.jsp.index_jsp</servlet-name>
<jsp-file>org.apache.jsp.index_jsp.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>org.apache.jsp.index_jsp</servlet-name>
<url-pattern>/index_jsp.jsp</url-pattern>
</servlet-mapping>
org.apache.jsp.index\u jsp
org.apache.jsp.index_jsp.jsp
org.apache.jsp.index\u jsp
/index_jsp.jsp
对于web.xml中的jsp映射,必须使用jsp文件标记
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>org.apache.jsp.index_jsp</servlet-name>
<jsp-file>org.apache.jsp.index_jsp.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>org.apache.jsp.index_jsp</servlet-name>
<url-pattern>/index_jsp.jsp</url-pattern>
</servlet-mapping>
org.apache.jsp.index\u jsp
org.apache.jsp.index_jsp.jsp
org.apache.jsp.index\u jsp
/index_jsp.jsp
@KVK:-你的URL是什么?你在浏览器的URL栏中写的是什么?@KVK:-如果你想直接访问jsp文件,你的URL应该是这样的localhost:8082/你的应用程序的根文件夹/你的文件名.extension如果我在web.xml中添加你的代码,那么我的服务器无法启动我能做什么do@KVK:-我的代码不会对服务器产生影响statup.这是您的服务器问题。您可以删除服务器,然后重新添加。只有在您知道的情况下,才能执行此操作。或者您可以清理项目。请尝试这两种解决方案。我认为这是您的内部服务器problem@KVK:-你的URL是什么?你在浏览器的URL栏中写了什么?@KVK:-如果你想直接访问jsp文件,你的URL应该是这样的localhost:8082/您的应用程序的根文件夹/您的文件名.extension如果我在web.xml中添加了您的代码,那么我的服务器无法启动我可以做什么do@KVK:-我的代码不会对服务器状态产生影响。这是您的服务器问题。您可以删除服务器并重新添加。只有在您知道的情况下才能执行此操作。或者您可以清理项目。请尝试这两种解决方案。我想这是您的内部服务器问题jsp的路径是什么?jsp的路径是什么?