问题
domain/Forum_show.action?pg=2&forum=java
How do I rewrite that to:
domain/forum/java/pg/2
回答1:
Use the URL structure you like right from the start. The ability to map to any URL structure is a feature of the Servlet API.
Also, you don't need to have an action extension (the .action part) in Struts2. In my opinion, creating bogus extensions never made sense.
Here are a few pages where I have talked about using Named Variable Pattern Matching in order to provide prettier URLs. I use this technique in all of my Struts2 apps and it yields much nicer URLs similar to your second example.
- NamedVariablePatternMatcher
- Better URLs with Struts2
回答2:
You may want to check Struts REST Plugin, which purpose is to follow Ruby on Rails URL style (just as you want).
回答3:
Both are good answers but you can use UrlRewritefilter. In this link there is an example of how to use in a Struts2 application.
来源:https://stackoverflow.com/questions/12073951/how-to-change-url-pattern-in-struts-action