struts2访问WEB-INF文件下内容

1、 WEB-INF下内容,通过浏览器下无法直接访问

2、 在配置action跳转的时候,默认type类型dispatcher对WEB-INF 是大小写敏感的,比如

      <result name="success"  >/web-inf/template/user.html</result> 是不能访问到html文件的,必须是

      <result name="success"  >/WEB-INF/template/user.html</result>

3、如果type不是dispatcher,比如是freemarker,则小写的web-inf也可以访问的资源,比如如下的配置

      

      <action name="userLogin" class="example.Login"  method="userLogin">
            <result name="success"  type="freemarker">/web-inf/template/user.html</result>
       </action>

 4、type不写是对web-inf大小写敏感的,因为默认是dispatcher,更改type的默认属性为freemarker可以实现忽略对web-inf的大小写

     更改方式:从strus2-core-2.1.6.jar 包里拷一份struts-default.xml到src下,在package name="struts-default"下找到result-type name="freemarker" 节点,为其添加属性default="true",同时删掉result-type name="dispatcher" 节点的default="true"属性

=============================

在ssh2+freemaker的开发中,可以修改默认的type为freemarker。可以方便的少写type="freemarker",但对刚接触框架的人来说,理解上可能一下子转不过弯。

猜你喜欢

转载自zhouchaofei2010.iteye.com/blog/1738439