0

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!

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
vmg
  • 9,920
  • 13
  • 61
  • 90

2 Answers2

2

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
  • 17,579
  • 5
  • 72
  • 84
1

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ý
  • 32,463
  • 16
  • 90
  • 116