我不想说如何配置 Struts2 处理的 url 后缀名,因为关于这方面的文章太多了,今天我说一说如何配置 Struts2 不处理的 url 后缀名。
在 struts.xml 或 struts.properties 配置文件中配置 struts.action.extension 项可以设置 Struts2 处理的 url 请求后缀名,
如:struts.action.extension = action, do
这样 url 是这样:http://www.mxjava.com/index.do
很多网站的 url 是没有后缀的,比如利用 ror 开发的网站的 url 类似这样:http://www.mxjava.com/index 。这样的 url 对搜索引擎更加友好。其实利用上面讲的 struts.action.extension 也可以让 Struts2 的 url 变成这样。很简单,只要将 struts.action.extension 设置为空即可。
如:struts.action.extension =
此时 url 是这样:http://www.mxjava.com/index
问题来了,服务器的某个目录下有个 html 文件是希望被访问的,这时在地址栏输入该 html 文件的地址 http://www.mxjava.com/10000.html 后画面上显示的并不是该 html 的内容,而的系统出错信息:
Struts has detected an unhandled exception:
# Messages: There is no Action mapped for namespace / and action name 10000.html.