struts2下无法用直接通过路径访问.jsp的页面:HTTP Status 403 - Access to the requested resource has been denied

struts2下无法用直接通过路径访问.jsp的页面

http://localhost:8081/struts2_020/index.jsp

访问会出错,

HTTP Status 403 - Access to the requested resource has been denied

type Status report

message Access to the requested resource has been denied

description Access to the specified resource has been forbidden.


Apache Tomcat/8.0.33

出错 可能的原因:

1.没有放在webroot目录下,放在WEB-INF目录中

WEB-INF下的东西是禁止直接访问的,要想让人访问最好不要放在这个目录下。如果一定放在那里。你可以使用:
request.getRequestDispatcher("/WEB-INF/test.jsp").forward(request,response);
直接添加一个链接那肯定是没发过去的。你可以先跳到一个jsp,那个jsp里写上上面的代码就可以了。

2.在web.xml文件中进行了配置

<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>

这个配置会导致无法访问.jsp页面,只能通过struts2.xml 中的action来调用。删掉就行

那么如果我们想要实现拒绝.jsp直接访问的功能是否就能这样用呢。通过这样的配置来实现这样的功能。

转载自:https://blog.csdn.net/mdq11111/article/details/51525931

猜你喜欢

转载自blog.csdn.net/hnnydxhxg/article/details/81304713
今日推荐