I faced with next task: I have an host, for example host.com and web-application on it.
Application written on Java (JSP/Servlets+Struts2).
I need to implement such HTTP-request to servlet mapping: if user enters address in browser like http://host.com/admin.action, where admin.action – existing action, defined in struts.xml, then render those struts2 action for user. If user enters something like http://host.com/abra-kadabra, (action abra-kadabra notdefined in struts.xml), then pass this request to some servlet or struts action.
Can somebody advice how to do such thing?
Thank you!
Servlet specification doesn’t give you many options. You can map your servlet to specific path (
/some/specific/path), to all paths under some hierarchy (/dir/*) or to some extension (*.action). Best what you can do is to map your servlet to*.action, and then determine action to be executed based onrequest.getRequestURI()orrequest.getServletPath().