rustybeanstalk
rustybeanstalk

Reputation: 2762

Multiple URLs serving the same static page in Tomcat and Jersey?

I am using backbone.js for to do client side routing on my web application.

In order for this client side routing to work, I need all URLs return the same html page, and the routing will then be done on that page in JavaScript.

I am using Jersey + Tomcat for my static pages and servlets. How do I have all URLs serve up the same page? (i.e all URLs matching MyWebbApp/App/** to serve up my index.html page).

Thanks in advance!

edit:

What regex would I use? I would like MyWebApp/App MyWebApp/App/ MyWebApp/App/other MyWebApp/App/other/other...

all to be included. I tried to do it but I could not get 1 regex to cover all those cases for some reason. The closest I got was:

@Path("MyWebApp/App/{some_var_name_i_never_use: .*}")

but this did not cover the MyWebApp/App or MyWebApp/App/ case.

Upvotes: 0

Views: 448

Answers (2)

condit
condit

Reputation: 10962

You could use Jersey's filter for static content. Here's a blog post about it. You'd just need to define another filter to handle mapping everything to your index.html page. Note that in Jersey 2.0 the parameter name was changed to jersey.config.servlet.filter.staticContentRegex.

Upvotes: 1

Shamis Shukoor
Shamis Shukoor

Reputation: 2515

You could use a servlet and redirect all the pages to a particular page

You could have a regex to get all the pages that need to be redirected

response.sendRedirect("page");

Upvotes: 0

Related Questions