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
Add a ment  | 

3 Answers 3

Reset to default 4

You 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
Add a ment  | 

3 Answers 3

Reset to default 4

You 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