我是否需要做任何事情来激活 Tomcat 来处理对 j_security_check 的调用?配置和 HTML 代码如下。我收到此错误:
错误信息
输入状态报告
消息/(上下文路径)/ProviderManager/j_security_check
描述请求的资源(/(上下文路径)/ProviderManager/j_security_check)不可用。
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_3_0.xsd">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<security-constraint>
<display-name>Constraint1</display-name>
<web-resource-collection>
<web-resource-name>ProviderManager</web-resource-name>
<description/>
<url-pattern>/ProviderManager/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<description/>
<role-name>tomcat</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/ProviderManager/login.jsp</form-login-page>
<form-error-page>/ProviderManager/error.jsp</form-error-page>
</form-login-config>
</login-config>
<security-role>
<description/>
<role-name>tomcat</role-name>
</security-role>
</web-app>
tomcat-users.xml
<tomcat-users>
<role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>
<user username="ide" password="mgPNx5x5" roles="manager-script,admin"/>
</tomcat-users>
login.html
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form action="j_security_check" method="POST">
Username:<input type="text" name="j_username"><br>
Password:<input type="password" name="j_password">
<input type="submit" value="Login">
</form>
</body>
</html>
提前致谢
吉多
最佳答案
登录表单页面中的 action
参数被解释为相对于登录页面 URL 的 URL,因此当您提交表单时,浏览器会向服务器发送带有该 URL 的 POST 请求/[上下文路径]/ProviderManager/j_security_check
。 servlet 容器使用 /[context-path]/j_security_check
作为对您的 webapp 的身份验证请求的路径。
以下任何一项都可以解决此问题:
- 将登录页面中的
action
参数更改为../j_security_check
。 - 将登录页面中的
action
参数修改为/[context-root]/j_security_check
- 将登录页面移动到应用程序上下文根目录。
关于java - Tomcat 上的 j_security_check,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10838296/