Jakarta ee tomcat中的安全web应用

Jakarta ee tomcat中的安全web应用,jakarta-ee,tomcat,Jakarta Ee,Tomcat,我有一个在ApacheTomcat中运行的web应用程序,我使用了“j_security_check”来保护这个应用程序。我的代码如下: login.jsp <div id="loginForm"> <form id="loginfrm" method="post" action="j_security_check"> <table> <tr> <td>Us

我有一个在ApacheTomcat中运行的web应用程序,我使用了“j_security_check”来保护这个应用程序。我的代码如下:

login.jsp

<div id="loginForm">
    <form id="loginfrm" method="post" action="j_security_check">
        <table>
            <tr>
                <td>User Name</td>
                <td><input type="text" id="name" name="j_username" size="20" /></td>
            </tr>
            <tr>
                <td>Password</td>
                <td><input type="password" id="phone" name="j_password" size="20" /></td>
            </tr>
            <tr>
                <td></td>
                <td align="right"><input type="submit" value="Login" id="submitButton"></td>
            </tr>
        </table>
    </form>    
</div>
请任何人告诉我哪里错了?

线路:

<form-login-page>/success.jsp</form-login-page>
这告诉tomcat,只要您到达一个受保护的页面,登录表单就位于
login.jsp
中。缺少的是实际需要验证才能查看的受保护页面的定义:

<security-constraint>
  <web-resource-collection>
    <web-resource-name>
      Entire Application
    </web-resource-name>
    <url-pattern>/success.jsp</url-pattern>
  </web-resource-collection>
  <auth-constraint>
    <role-name> 'the name of the group with access' </role-name>
  </auth-constraint>
</security-constraint>

整个应用程序
/success.jsp
)


当您点击
http://localhost:8080/succes.jsp
您应该被重定向到登录页面,在收到一组有效的凭据后,将其发送到
/success.jsp
,并将一组错误的凭据发送到
/error.jsp
我做的几件事解决了我的问题。希望这对你也有帮助

1-更改此项:

致:


2-清除缓存

3-代替打字

http://somelocalhost:8080/you_web_app_name/some_login.jsp

类型:


http://somelocalhost:8080/you_web_app_name

:@rmarimon:这很有效,您的答案非常有用,顺便问一下,是否可以在数据库中存储用户名和密码并进行如下检查?当然,您可以按照链接[以使数据库连接正常]。
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Login Success</h1>
    </body>
</html>
HTTP Status 400 - Invalid direct reference to form login page

type Status report

message Invalid direct reference to form login page

description The request sent by the client was syntactically incorrect (Invalid direct reference to form login page).
Apache Tomcat/7.0.22
<form-login-page>/success.jsp</form-login-page>
<form-login-page>/login.jsp</form-login-page>
<security-constraint>
  <web-resource-collection>
    <web-resource-name>
      Entire Application
    </web-resource-name>
    <url-pattern>/success.jsp</url-pattern>
  </web-resource-collection>
  <auth-constraint>
    <role-name> 'the name of the group with access' </role-name>
  </auth-constraint>
</security-constraint>
<form method="POST" action="<%=request.getContextPath()%>/j_security_check">