2009-12-15 116 views
0

Servlet的web.xml中验证我有一个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它允许他们两个网址应显示在同一个页面,都应该被允许。我在这里做错了什么?

回答

4

我觉得做事情会指定/*赶上默认值,不喜欢/somethingElse.jsp特定的模式,以赶上那是 index.jsp的任何其他页面。希望你的顶级“目录”不是很混乱。

+2

你不需要考虑。你是对的:) – BalusC 2009-12-16 19:00:00

+2

我要采取这种说法,用大写字母打印出来,将它挂在桌子上并挂起来:) – 2009-12-16 19:14:15