gpt4 book ai didi

spring-mvc - 在 DispatcherServlet 中找不到名称为 'appServlet' 的带有 URI [/pms/j_spring_security_check] 的 HTTP 请求的映射

转载 作者:行者123 更新时间:2023-12-03 16:25:01 27 4
gpt4 key购买 nike

我开发了一个 Spring 应用程序,并在其中实现了与登录和注销功能的 Spring 安全集成。我在 xml 配置中使用了 Spring 安全性。但是当我登录系统时,它为我显示 404。控制台告诉我, 在 DispatcherServlet 中找不到名称为“appServlet” 的带有 URI [/pms/j_spring_security_check] 的 HTTP 请求的映射

但我无法理解这个错误。我错过了什么?

我的 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">

<!-- The definition of the Root Spring Container shared by all Servlets
and Filters -->

<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/spring-security.xml</param-value>
</context-param>

<!-- Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/</url-pattern>
</filter-mapping>
</web-app>

我的 Controller 方法:
@RequestMapping(value="/login", method = RequestMethod.GET)
public ModelAndView printWelcome() {
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("message", "Spring security allows you");
modelAndView.setViewName("loginForm");
return modelAndView;
}

我的 spring-security.xml :
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">

<http auto-config="true">
<intercept-url pattern="/loginForm"/>
<intercept-url pattern="/" access="ROLE_USER" />
<form-login login-page="/loginForm"
default-target-url="/login" always-use-default-target="true"
authentication-failure-url="/loginForm?login_error=1" />
<logout logout-success-url="/loginForm" />
</http>

<authentication-manager>
<authentication-provider>
<user-service>
<user name="a2ztechguide" password="123456" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>

</beans:beans>

我的登录页面的 :
<body>
<table>
<tr>
<td valign="top"><c:if test="${not empty param.login_error}">
<font color="red"> Invalid user name or password, try again.
<br /> <br />
</font>
</c:if>
<form name="login_form"
action="<c:url value='j_spring_security_check'/>" method="POST">
<div>
<table width="40%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top">
<table border="0" cellspacing="0" cellpadding="4" width="40%">
<tr>
<td colspan="2">Custom Login Form
<hr width="100%" size="1" noshade align="left">
</td>
<td></td>
</tr>
<tr>
<td width="80">Username</td>
<td valign="top" align="left"><input type='text'
id='username' size="30" maxlength="40" name='j_username'
value='<c:if test="${not empty param.login_error}">
<c:out value="${SPRING_SECURITY_LAST_USERNAME}"/>
</c:if>' />
</td>
</tr>
<tr>
<td width="80">Password</td>
<td valign="top" align="left"><input type='password'
name='j_password' size="30" maxlength="30"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit" /></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</form></td>
</tr>
</table>
</body>

请帮我。

最佳答案

我最终通过修改声明我的自定义登录表单页面的行解决了这个问题。

添加处理-url="/j_spring_security_check":

<form-login login-page="/login" default-target-url="/admin" login-processing-url="/j_spring_security_check" authentication-failure-url="/login?error" username-parameter="username" password-parameter="password"/>

到我的 security-context.xml 页面

关于spring-mvc - 在 DispatcherServlet 中找不到名称为 'appServlet' 的带有 URI [/pms/j_spring_security_check] 的 HTTP 请求的映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24321169/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com