我是 Tomcat 的新手,了解 servlet 映射,但希望我可以对驻留在 webapp/文件夹中的 html 文件进行一些映射。
我有一个简单的 javascript 网络应用程序,它位于 webapp/index.html 中。因为我搞乱了 javascript 中的 url,所以我想让映射/console/* 到 webapp/index.html 成为可能。例如/console/hi 和/console/bye 都应该加载 webapp/index.html。
这可能吗?如果是,怎么办?
最佳答案
您可以将 index.html 文件更改为相同的 index.jsp 文件 然后在 web.xml 中使用这个映射
<servlet>
<servlet-name>index</servlet-name>
<jsp-file>index.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>index</servlet-name>
<url-pattern>/console/*</url-pattern>
</servlet-mapping>
我认为这是最简单的方法。
关于java - 如何将所有 url 映射到单个 .html 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11679794/