struts2 报403 错误

来源:互联网 发布:网络限制不能玩游戏 编辑:程序博客网 时间:2024/06/01 09:39

好久没有接触struts2了,今天在写一个简单的网页(jsp)的时候,在整合了struts2时发现一个问题。

详情:

  jsp页面:index.jsp:输入用户名,登陆

                  login.jsp:登陆之后进入login页面:hello

  struts2.xml:

  <action name="login" class = "com.cyan.cloder.action.UserAction" method="addUser">
          <result name="success">view/regist.jsp </result>
   </action>

UserAction:

   就一个execute:return SUCCESS;

启动就报了403的错误。HTTP Status 403 - Access to the requested resource has been denied

后来发现是因为web.xml的问题:

原web.xml:

 <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>/*</url-pattern>
    </filter-mapping>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

    <!-- Restricts access to pure JSP files - access available only via Struts action -->
    <security-constraint>
        <display-name>No direct JSP access</display-name>
        <web-resource-collection>
            <web-resource-name>No-JSP</web-resource-name>
            <url-pattern>*.jsp</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>no-users</role-name>
        </auth-constraint>
    </security-constraint>

    <security-role>
        <description>Don't assign users to this role</description>
        <role-name>no-users</role-name>
    </security-role>

更换的web.xml

<filter>
  <filter-name>struts2</filter-name>
  <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
 </filter>
 <!-- 让Struts 2的核心Filter拦截所有请求 -->
 <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

that's all get



0 0
原创粉丝点击