如题。
还有个问题需要大家解决:就是网站的地址容错率:
假设我的网站是
http://localhost/myWeb
我的struct.xml如此配置: <package name="back" namespace="/all" extends="struts-default">
<action name="*_*" class="action.{1}Action" method="{2}">
<result name="success"> /WEB-INF/jsp/{1}/{1}_{2}_success.jsp</result>
<result name="error"> /WEB-INF/jsp/{1}/{1}_{2}_error.jsp</result>
</action>
</package>
       <!--这里是为了容错的-->
<package name="a" namespace="" extends="struts-default">
<action name="*">
<result>/error.html</result>
</action>
</package>如果不写下面那个package,如果我访问:
http://localhost/myWeb/xxx/xx/xx/xxx(或xxx.action)
那么就会出错,不友好。下面那个package是为了容错
写了,如果我访问上述网页,就会提交到我下面的里面
但是我的error.jsp是没有的,因为我在web.xml中配置了: <error-page>  
    <error-code>400</error-code>  
    <location>/WEB-INF/errors/fileNotFind.jsp</location>  
    </error-page>  
    <!-- 404 页面不存在错误 -->  
    <error-page>  
    <error-code>404</error-code>  
    <location>/WEB-INF/errors/fileNotFind.jsp</location>  
   </error-page> 找不到error.jsp页面,属于404错误,就会返回fileNotFind.jsp页面。
但是这有个问题,如果我访问的是:
http://localhost/myWeb/xxx/../xxx.任意后缀名
如果不存在的话,就会自动转到的我的fileNotFind.jsp
这里的漏洞就是:
http://localhost/myWeb/all/xx/xx
就会有问题,这个请求会提交到第一个package
那怎么办?
我的意思你们明白吗?我在线等。

解决方案 »

  1.   

    可以有多个action

    <constant name="struts.i18n.encoding" value="UTF-8" />
    <!--struts.objectFactory 将操作交给Spring去做 -->
    <constant name="struts.objectFactory" value="spring" />
    <!-- 设置Action访问时的扩展名 -->
    <constant name="struts.action.extension" value="php,htm,asp" />
    <!-- 开发模式,提供更友好的排错信息和自动重新加载配置文件 -->
    <constant name="struts.devMode" value="true" />
    <package name="itv" extends="struts-default">
    <action name="*Live" method="{1}"
    class="channelAction">
    <result name="list">/Live.jsp</result>
    <result name="input">/Live.jsp</result>
    </action>
    <action name="*Demand" method="{1}"
    class="categoryAction">
    <result name="listTitle">/Demand.jsp</result>
    <result name="input">/index.jsp</result>
    </action>
    <action name="*Review" method="{1}"
    class="reviewAction">
    <result name="list">/Review.jsp</result>
    <result name="input">/Review.jsp</result>
    </action>
    <action name="*Share" method="{1}"
    class="shareAction">
    <result name="friends">/share_friends.jsp</result>
    <result name="shar">/share_ok.jsp</result>
    <result name="share">/Share.jsp</result>
    <result name="empty">/share_friends.jsp</result>
    <result name="add">/add_friend.jsp</result>
    <result name="input">/Review.jsp</result>
    </action>

    <action name="*Action" method="{1}"
    class="collectionAction">
    <result name="myItv">/MyItv.jsp</result>
    <result name="input">/index.jsp</result>
    </action>
    <action name="*Member" method="{1}"
    class="memberAction">
    <result name="find">/add_friend.jsp</result>
    <result name="forword">/forword.jsp</result>
    <result name="input">/index.jsp</result>
    </action>
    </package>
      

  2.   

     <error-page>  
        <error-code>404</error-code>  
        <location>/WEB-INF/errors/fileNotFind.jsp</location>  
      </error-page> 
    怎么了?
      

  3.   

    这个是可以自己定义错误页面,比如你没有那个result,安装strtus2会有一个错误页面 no result 这个时候给客户显示不友好,我们可以自己定义。定义一个错误页面进行调转。除了可以在web.xml配置页面找不到的错误外,还可以在action中定义。