【发布时间】:2018-07-19 02:43:50
【问题描述】:
我使用eclipse制作了一个简单的表单认证tomcat,其中需要名称和密码才能访问。但是,当我将用户名和密码放入文件 tomcat-users.xml 时,我收到错误 HTTP 状态 403,这意味着访问被拒绝。
我猜问题出在 web.xml 或 server.xml 中。我知道错误不在 tomcat-users.xml 中,因为我尝试了所有方法,但总是遇到相同的错误。
文件 web.xml 中相对于我的 TestServlet 的脚本是:
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>test.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
<security-constraint>
<web-resource-collection>
<web-resource-name>Wildcard means whole app requires authentication</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>tomcat</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/login.html</form-login-page>
<form-error-page>/login-failed.html</form-error-page>
</form-login-config>
</login-config>
PS:当我输入错误的凭据时,我得到页面 login-failed.html,所以当我输入错误的凭据时一切正常。 PS:文件tomcat-users.xml中的代码是:
<tomcat-users>
<role rolename="manager"/>
<user username="admin" password="admin" roles="manager"/>
</tomcat-users>
有人可以帮我找出问题吗?
【问题讨论】:
标签: java xml eclipse tomcat http-status-code-403