How to map a dynamic profile number to a servlet?
How could I map a dynamic profile number to a servlet for example
http://stackoverflow.com/questions/2585407
I want to map this 2585407 to a servlet is this possible?
T开发者_Python百科hanks
Yes, and there are multiple options:
- use an UrlRewriteFilter to rewrite the given url to
questions?id=2585407
, then read the request parameter - use some framework like Spring-MVC that supports beatiful URLs
- map the servlet to
/questions/*
(in web.xml) and then parse thegetRequestURI()
(by stripping the prefix and therequest.getContextPath()
)
use following pattern in URL mapping
/questions/*
If your <url-mapping>
is set to
/questions/*
Then you would get your question id by using request.getPathInfo()
(request being HttpServletRequest
).
精彩评论