1. 程式人生 > >struts2下無法用直接通過路徑訪問.jsp的頁面:HTTP Status 403 - Access to the requested resource has been denied

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