views:

32

answers:

2

Hi all!

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!

+1  A: 

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 on request.getRequestURI() or request.getServletPath().

Peter Štibraný
+1  A: 

You could use Tuckey's very powerful URLRewriteFilter. i.e.

<rule>
   <from>^/abra-kadabra$</from>
   <to>/admin.action</to>
</rule>

This rule would forward all browser requests on "/abra-kadabra" to "/admin.action" transparent to the user.

kaliatech