struts2下無法用直接通過路徑訪問.jsp的頁面

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直接訪問的功能是否就能這樣用呢。通過這樣的配置來實現這樣的功能。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章