how to change url pattern in struts action

佐手、 提交于 2019-12-04 05:50:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!