【问题标题】:Servlet web.xml authentication for welcome page欢迎页面的 Servlet web.xml 身份验证
【发布时间】:2010-12-26 17:12:50
【问题描述】:

我有一个 web.xml,它看起来像:

<web-app>

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

<security-constraint>
  <web-resource-collection>
    <web-resource-name>Default</web-resource-name>
    <url-pattern>/</url-pattern>
  </web-resource-collection>
  <auth-constraint/>
</security-constraint>

<security-constraint>
  <web-resource-collection>
    <web-resource-name>Index page</web-resource-name>
    <url-pattern>/index.jsp</url-pattern>
    <url-pattern>/</url-pattern>
    <http-method>GET</http-method>
    <http-method>HEAD</http-method>
  </web-resource-collection>
</security-constraint>
...

我们希望默认拒绝对资源的访问,并指定我们希望允许访问的资源。

如果用户转到 http://localhost:8080/,他们会被拒绝访问,但是,如果转到 http://localhost:8080/index.jsp,则允许他们进入。两个 URL 应该显示相同页面,并且两者都应该被允许。我在这里做错了什么?

【问题讨论】:

    标签: java servlets jetty web.xml


    【解决方案1】:

    我认为要做的事情是指定/* 来捕获默认值,并执行特定的模式(例如/somethingElse.jsp)来捕获 index.jsp 的任何其他页面。希望您的顶级“目录”不是很混乱。

    【讨论】:

    • 我要把那份声明拿下来,用大字打印出来,装裱起来挂在我的桌子上 :)
    猜你喜欢
    • 1970-01-01
    • 2015-06-26
    • 2019-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-06
    • 2013-05-14
    • 2012-09-04
    相关资源
    最近更新 更多