Java 在Tomcat中进行表单身份验证时出错

Java 在Tomcat中进行表单身份验证时出错,java,authentication,tomcat,Java,Authentication,Tomcat,我想让身份验证由Tomcat控制。为了测试它,我创建了简单页面、登录页面和登录错误页面 身份验证似乎起了作用。当我输入错误的登录名或密码时,我会看到登录错误页面。但当我输入正确的登录名和密码时,我看到: type Status report message Access to the requested resource has been denied description Access to the specified resource (Access to the requested

我想让身份验证由Tomcat控制。为了测试它,我创建了简单页面、登录页面和登录错误页面
身份验证似乎起了作用。当我输入错误的登录名或密码时,我会看到登录错误页面。但当我输入正确的登录名和密码时,我看到:

type Status report

message Access to the requested resource has been denied

description Access to the specified resource (Access to the requested resource has been denied) has been forbidden.
这是我的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <security-constraint>
        <web-resource-collection>
            <url-pattern>/protected.jsp</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>*</role-name>
        </auth-constraint>
    </security-constraint>
    <login-config>
        <auth-method>FORM</auth-method>
        <form-login-config>
            <form-login-page>/login.jsp</form-login-page>
            <form-error-page>/loginError.jsp</form-error-page>
        </form-login-config>
    </login-config>

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

30
/protected.jsp
*
形式
/login.jsp
/loginError.jsp
index.jsp
这是我的tomcat-users.xml

<tomcat-users>

  <role rolename="tomcat"/>
    <role rolename="admin"/>
    <role rolename="manager"/>
    <user password="tomcat" roles="tomcat,manager,admin" username="tomcat"/>
    <user password="proger" roles="tomcat" username="proger"/>
</tomcat-users>

我的login.jsp看起来像:

<html>
    <body>
        <form id="loginForm" method="post" action="j_security_check">
            <p>
                Username: <input type="text" name="j_username" id="j_username" />
                <br/>
                Password: <input type="password" name="j_password" id="j_password" />
                <br/>
                <button type="submit">login</button>
            </p>
        </form>
    </body>
</html>


用户名:

密码:
登录

我使用NetBeans 6.9.1部署它。我使用Tomcat 6.0.29。 有什么不对劲? 提前感谢。

使用

   <auth-constraint>
        <role-name>*</role-name>
    </auth-constraint>

*
要求您还定义“有效”角色

<security-role>
      <role-name>admin</role-name>
</security-role>
<security-role>
     <role-name>user</role-name>
</security-role>

管理
用户
如果用户输入了有效的名称/通行证,但仅在“dimwit”角色中,他们将使用

   <auth-constraint>
        <role-name>*</role-name>
    </auth-constraint>

*
要求您还定义“有效”角色

<security-role>
      <role-name>admin</role-name>
</security-role>
<security-role>
     <role-name>user</role-name>
</security-role>

管理
用户

如果用户输入了有效的名称/密码,但仅在“dimwit”角色中,他们将被拒绝访问

尝试使用明确的角色名称,如
tomcat
,而不是通配符
*
。我记得有一些与此相关的问题,但如果在最近的Tomcat6中没有修复,我会感到惊讶,因为它没有修复。谢谢你的建议。这很有帮助。尝试使用一个明确的角色名,比如
tomcat
,而不是通配符
*
。我记得有一些与此相关的问题,但如果在最近的Tomcat6中没有修复,我会感到惊讶,因为它没有修复。谢谢你的建议。这有帮助。