3

I'd like to use this kind of a pattern for my Java web app:

<url-pattern>/*/test.html</url-pattern>

and then parse the URL in the servlet to get what the value of the star is, and use that value to query a different table in the database.

However this seems to be an illegal pattern for Tomcat. Is there any way I can achieve this without having to hard code the bit between the slashes?

(example uses in case you're wondering what the context is: /vancouver-hotel/rooms.html, /seattle-hotel/rooms.html)

3 Answers 3

3

Best way is to rearrange your URL structure to /hotels/<cityname> and let a HotelServlet listen on /hotels/* and get the <cityname> as pathinfo using request.getPathInfo(). You can use the usual java.lang.String methods to parse the pathinfo further. For example a split("/") and then storing the parts as a request attribute or something else which can be accessed by business/domain objects.

Sign up to request clarification or add additional context in comments.

Comments

1

You can use a url rewriting filter:

http://tuckey.org/urlrewrite/

Comments

0

Easily done with a GET parameter:

http://localhost:8080/rooms?city=vancouver

2 Comments

Not SEO friendly. Query parameters are ignored.
Map everything to rooms and let the servlet sort things out after fetching the city out of query parameters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.