gpt4 book ai didi

java - 如何在web.xml中映射jsp类?

转载 作者:太空宇宙 更新时间:2023-11-04 13:05:10 25 4
gpt4 key购买 nike

我正在尝试将 tomcat 服务器文件夹中的 org.apache.jsp 文件夹中提供的已编译的 jsp 类映射到 web.xml 文件,以便我不想发送我的 jsp 代码。

我正在使用以下代码,但收到HTTP 状态 404 -。我交叉检查,路径是正确的,并且类文件也可以在该路径中使用,我不知道为什么会收到此错误。

<?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>

谁能帮我解决这个问题吗?

最佳答案

您必须使用 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>

关于java - 如何在web.xml中映射jsp类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34541258/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com