admin管理员组文章数量:1023827
I'm new to Tomcat, and understand servlet-mapping, but was hoping I could do some mapping to a html file residing in the webapp/ folder.
I have a simple javascript web application that resides as webapp/index.html. Since I'm messing with the url in javascript, I want to make it possible to map /console/* to hit webapp/index.html. For example /console/hi and /console/bye should both load up webapp/index.html.
Is this possible? If so, how?
I'm new to Tomcat, and understand servlet-mapping, but was hoping I could do some mapping to a html file residing in the webapp/ folder.
I have a simple javascript web application that resides as webapp/index.html. Since I'm messing with the url in javascript, I want to make it possible to map /console/* to hit webapp/index.html. For example /console/hi and /console/bye should both load up webapp/index.html.
Is this possible? If so, how?
Share Improve this question asked Jul 27, 2012 at 0:08 Lewis ChungLewis Chung 2,3271 gold badge20 silver badges16 bronze badges 1- 1 I think that what you need is a filter, for a particular family of URLs, and that filter can do the redirecting/forwarding as necessary. – Pointy Commented Jul 27, 2012 at 0:18
3 Answers
Reset to default 4You can change your index.html file to same index.jsp file and then use this mapping in 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>
I think it is the easiest way.
Like @Pointy said, you'll need a filter, that will receive all requests and redirect to the .hmtl page you want...
Here is a link with a simple filter implementation.
Hope it helps
I've published a Java servlet filter implementation that does what you need to Github. The code is pretty simple, and I expect you might want to customize it to your own needs.
https://github./lookfirst/history-api-fallback
I'm new to Tomcat, and understand servlet-mapping, but was hoping I could do some mapping to a html file residing in the webapp/ folder.
I have a simple javascript web application that resides as webapp/index.html. Since I'm messing with the url in javascript, I want to make it possible to map /console/* to hit webapp/index.html. For example /console/hi and /console/bye should both load up webapp/index.html.
Is this possible? If so, how?
I'm new to Tomcat, and understand servlet-mapping, but was hoping I could do some mapping to a html file residing in the webapp/ folder.
I have a simple javascript web application that resides as webapp/index.html. Since I'm messing with the url in javascript, I want to make it possible to map /console/* to hit webapp/index.html. For example /console/hi and /console/bye should both load up webapp/index.html.
Is this possible? If so, how?
Share Improve this question asked Jul 27, 2012 at 0:08 Lewis ChungLewis Chung 2,3271 gold badge20 silver badges16 bronze badges 1- 1 I think that what you need is a filter, for a particular family of URLs, and that filter can do the redirecting/forwarding as necessary. – Pointy Commented Jul 27, 2012 at 0:18
3 Answers
Reset to default 4You can change your index.html file to same index.jsp file and then use this mapping in 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>
I think it is the easiest way.
Like @Pointy said, you'll need a filter, that will receive all requests and redirect to the .hmtl page you want...
Here is a link with a simple filter implementation.
Hope it helps
I've published a Java servlet filter implementation that does what you need to Github. The code is pretty simple, and I expect you might want to customize it to your own needs.
https://github./lookfirst/history-api-fallback
本文标签: javaHow to map all urls to a single html pageStack Overflow
版权声明:本文标题:java - How to map all urls to a single .html page - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745586702a2157638.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论