j_security_check总是返回失败

时间:2014-03-04 07:51:19

标签: java jsp tomcat servlets j-security-check

我试着在学校完成作业。但是,我面临着问题。

j_security_check总是返回失败。我试着谷歌很多文件。但它无法解决这个问题。

任何人都有一些想法?以及如何在登录后重定向新页面,现在我可以看到我只能回复一个文本。

也许我错了<realm-name>UserDatabase</realm-name>,但我不知道如何改变它。

感谢您的阅读。

Login.html文件:

<form id="login" method="post" action="j_security_check" >
        <input name="j_username" type="text" value="123">
        <input name="j_password" type="text" value="123">
        <input type="submit" value="Login" />
    </form>

LoginType.java

 protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    //        processRequest(request, response);
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
        out.println("Success");
    } finally {
        out.close();
    }
}

web.xml文件:

<servlet>
    <servlet-name>Logintype</servlet-name>
    <servlet-class>Logintype</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Logintype</servlet-name>
    <url-pattern>/Logintype</url-pattern>
</servlet-mapping>
<security-constraint>
    <web-resource-collection>
        <web-resource-name>Vaadin application</web-resource-name>
        <url-pattern>/Logintype</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>users</role-name>
    </auth-constraint>
</security-constraint>
<login-config>
    <auth-method>FORM</auth-method>
    <realm-name>UserDatabase</realm-name>
    <form-login-config>
        <form-login-page>/Login.html</form-login-page>
        <form-error-page>/Fail.html</form-error-page>
    </form-login-config>
</login-config>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>

tomcat-user.xml文件:

<tomcat-users>
<role rolename="tomcat"/>
 <role rolename="role1"/>
 <role rolename="users"/>
 <user username="123" password="123" roles="users"/>
 <user username="tomcat" password="tomcat" roles="tomcat"/>
 <user username="both" password="tomcat" roles="tomcat,role1"/>
 <user username="role1" password="tomcat" roles="role1"/>
  </tomcat-users>

server.xml

  <Realm className="org.apache.catalina.realm.LockOutRealm">
    <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
           resourceName="UserDatabase"/>
  </Realm>

0 个答案:

没有答案