我是否必须做任何事情来激活Tomcat来处理对j_security_check的调用?配置& HTML代码如下。我收到了这个错误:
错误消息
类型状态报告
消息 /(上下文路径)/ ProviderManager / j_security_check
description 请求的资源(/(上下文路径)/ 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>
由于式提前,
圭
答案 0 :(得分:11)
登录表单页面中的action
参数被解释为相对于登录页面的URL的URL,因此当您提交表单时,浏览器会向服务器发送一个POST请求,其URL为{{1 }}。 servlet容器使用/[context-path]/ProviderManager/j_security_check
作为对webapp的身份验证请求的路径。
以下任何一项都应解决此问题:
/[context-path]/j_security_check
参数更改为action
。../j_security_check
参数更改为action
答案 1 :(得分:0)
您无需配置任何内容。
项目的目录结构是什么?问题是一条道路。
将login.jsp和error.jsp放在WebContent / pages中并尝试:
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/pages/login.jsp</form-login-page>
<form-error-page>/pages/error.jsp</form-error-page>
</form-login-config>
答案 2 :(得分:0)
您的tomcat-users.xml无效。
<tomcat-users>
<role rolename="manager-script"/>
<role rolename="manager-gui"/>
<role rolename="admin"/>
<user username="ide" password="whatever" roles="manager-script,admin"/>
</tomcat-users>
您应该删除空描述标记:<description/>