【问题标题】:How avoid direct access to a jsp page如何避免直接访问jsp页面
【发布时间】:2014-10-28 18:33:01
【问题描述】:

我创建了一个登录页面,获取用户名和密码,点击后会转到 JSP。 如何隐藏用户无法直接访问的 JSP 页面。 在下面的代码中,如果用户直接输入他/她将收到的 JSP 页面地址:

HTTP Status 500 - Internal Server Error

我希望用户重定向到登录页面。

   String username = request.getParameter("username");
    String password = request.getParameter("password");
    if(username == null || password == null){
        response.sendRedirect("facultylogin.html");

    }
    UpdateFaculty fl = new UpdateFaculty();
    if(fl.facultyCheck(username, password)){
        Teacher t = fl.fillForm(username, password);

【问题讨论】:

    标签: jsp


    【解决方案1】:

    只需将JSP文件放在WEB-INF文件夹下,容器永远不会直接服务它。但是您可以从另一个 servlet(包括 JSP)转发到它。

    【讨论】:

      【解决方案2】:

      或者您可以将您的 jsp 文件放在一个名为 pages 的文件夹中,并在 web.xml 中添加一个安全约束

      <security-constraint>
          <web-resource-collection>
              <web-resource-name>JSP Files</web-resource-name>
              <description>No direct access to JSP files</description>
              <url-pattern>/pages/*</url-pattern>
              <http-method>POST</http-method>
              <http-method>GET</http-method>
          </web-resource-collection>
          <auth-constraint>
              <description>No direct browser access to JSP files</description>
              <role-name>NobodyHasThisRole</role-name>
          </auth-constraint>
      </security-constraint>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-11-09
        • 2016-02-03
        • 1970-01-01
        • 1970-01-01
        • 2017-11-22
        • 1970-01-01
        • 2023-03-05
        • 2020-02-28
        相关资源
        最近更新 更多