第一:url重写的方式。url重写就是将浏览器的一个请求在服务器端重定向到另一个可以处理请求的url上。
这样的好处是地址统一,且利于搜索引擎。详见:http://blog.csdn.net/java2000_net/article/details/2935913
第二:struts本身就支持风格化的url
步骤:(1)、增加struts的扩展名<constant name="struts.action.extension" value="html," />,struts2拥有了两个扩展名html和空
(2)、 在web.xml中配置struts2的核心控制器将*.html,*的请求交给struts2来处理
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
(3)、配置具体的action
<package name="question" extends="examination">
<action name="question_toAnalysis_*" class="com.center.web.QuestionAction" method="toAnalysis">
<param name="question.id">{1}</param>
<result name="success" type="dispatcher">/WEB-INF/web/question/toAnalysis.jsp</result>
</action>
</package>
这样一个http://360sat.cn/question_toAnalysis_3.html 就映射到了http://360sat.cn/question_toAnalysis?question.id=3
例如:http://360sat.cn/question_toAnalysis_3.html
重定向到http://360sat.cn/question_toAnalysis?question.id=3
这样的好处是地址统一,且利于搜索引擎。详见:http://blog.csdn.net/java2000_net/article/details/2935913
第二:struts本身就支持风格化的url
步骤:(1)、增加struts的扩展名<constant name="struts.action.extension" value="html," />,struts2拥有了两个扩展名html和空
(2)、 在web.xml中配置struts2的核心控制器将*.html,*的请求交给struts2来处理
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
(3)、配置具体的action
<package name="question" extends="examination">
<action name="question_toAnalysis_*" class="com.center.web.QuestionAction" method="toAnalysis">
<param name="question.id">{1}</param>
<result name="success" type="dispatcher">/WEB-INF/web/question/toAnalysis.jsp</result>
</action>
</package>
这样一个http://360sat.cn/question_toAnalysis_3.html 就映射到了http://360sat.cn/question_toAnalysis?question.id=3