【发布时间】:2017-07-02 18:35:27
【问题描述】:
登录页面
<form method='post' action='j_security_check'>
<input type='text' name='j_username'>
<input type='password' name='j_password'>
</form>
来自 web.xml 的内容
<web-app>
<security-constraint>
<web-resource-collection>
<web-resource-name>User Auth</web-resource-name>
<url-pattern>/auth/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
<role-name>manager</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>error.jsp</form-error-page>
</form-login-config>
</login-config>
</web-app>
基于表单的身份验证工作正常。但是,如果我直接从http://localhost:8080/index.jsp/j_security_check?j_username=admin&j_password=admin 访问 index.jsp 将无法正常工作。
为什么它不起作用?
【问题讨论】:
-
method='post'但是浏览器发送了一个 GET 请求(据我所知),如果你真的想这样做,你也需要管理 GET 请求。 (但真的有必要吗?如果你真的需要,请使用重定向页面) -
当您在表单中使用 method='post' 时,请求将作为帖子处理 - 但是,当您只是按照您的指示直接传递查询参数时 -请求将作为 get(即 != post)处理,因此不起作用