在名称为“appServlet”的 DispatcherServlet 中未找到带有 URI [/pms/j_spring_security_check] 的 HTTP 请求的映射

2024-03-04

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

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

My 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>

我的控制器方法:

@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;
    }

My 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>

And 我的登录页面:

<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 页面

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在名称为“appServlet”的 DispatcherServlet 中未找到带有 URI [/pms/j_spring_security_check] 的 HTTP 请求的映射 的相关文章

随机推荐

  • matlab从数组中随机选择数字及其索引

    我有一个数组 c 1 2 3 4 5 可能有多个重复数字 我想从数组中随机选择一个元素及其索引 有谁能够帮助我 你可以find http in mathworks com help matlab ref find html refresh
  • Common Lisp 的 Man 或 javadoc 风格的文档

    是否有任何类型的常见 lisp 文档 例如 javadoc man 甚至类似智能感知的弹出窗口 我刚刚开始学习common lisp 手上记忆力不够 我正在使用 emacs 和 slime 它有制表符补全功能 但看起来信息量不大 Thank
  • 如果我在代码中犯了一个错误并导致JavaScript中出现无限循环并且它不断调用alert(),有没有办法停止循环?

    有时我使用调试代码来警告 javascript 中的某些内容 例如 匹配正则表达式中的某些内容 但忘记了修饰符 并且警报处于无限循环中 或者如果循环与模式匹配 300 次 如果使用 Firefox 警报会不断出现 甚至无法关闭选项卡 窗口或
  • 将 PDF 转换为图像,无需非 python 依赖项

    我想创建一个可以部署到其他计算机上的exe 该程序需要能够读取 pdf 并将其转换为图像 但我不希望其他用户必须下载依赖项 我的理解是 py2image 和 wand 都需要外部依赖项 如果您转换为 exe 其他用户也需要自己下载依赖项 还
  • Spring Remoting 序列化和反序列化

    我们在项目中使用 Spring Remoting 一段时间了 它与其他一些系统一起使用来访问我们的网络服务 我们目前正在研究网络服务采用的参数 但与此同时 我们正在努力独立于消费者 所以 目前我的问题是关于序列化和反序列化在 Spring
  • 将 Objective-C (#define) 宏转换为 Swift

    简而言之 我正在尝试转换 define宏转换为某种原生 Swift 数据结构 只是不确定如何或何种类型 Details 我想尝试并复制以下内容 define从 Objective C 到 Swift 资料来源 JoeKun FileMD5H
  • As3 复制对象

    有时我们需要克隆一个对象 但是如果一个显示对象有一些子对象并使用如下函数 function clone source var b ByteArray new ByteArray b writeObject source b position
  • Socket.io 1.0.5:如何保存会话变量?

    不幸的是 socket io 开发团队决定弃用函数 set 和 get 问题是这两个函数允许我们将变量保存到会话中 所以我的问题是 socket io 1 0 5 上的以下代码等效于什么 socket set mySessionVar my
  • 为什么 R 计算在我的虚拟机中不一致?

    我正在尝试构建一个新的虚拟机R以及下面的软件包作为R server根据我的计算 this is how I install my R packages function install packages folder dir create
  • 删除带有条件的
    标记的多个实例

    正如我在帖子中所说 我只是一个正则表达式学徒 一切都从这个线程开始 Stackoverflow 从预标记内部删除 br https stackoverflow com questions 30577912 remove br from in
  • 列表框多值选择

    我已经根据查询输出创建了表单 我使用了三个组合框和一个列表框 第一个组合框为我提供了部门列表 选择第二个组合框为我提供了该部门的位置 不同 第三个组合框为我提供了该位置的 不同 项目 然后下一个是显示该项目的一些代码的列表框 问题是我只能从
  • QCoreApplication 带有 WMI 的 QApplication

    我在MSDN网站上找到了一些WMI C 应用示例 我已经尝试过以下链接中的代码 http msdn microsoft com en us library aa390423 28v VS 85 29 aspx http msdn micro
  • R - 将 R 模型序列化为 JSON [关闭]

    Closed 此问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 是否有一些好的 R 包可以将预测模型和其他复杂对象与 JSON 相互转换 我从这个例子中得到了线性回归模
  • 如果下一个元素为空则隐藏该元素

    我有以下代码 h3 class hideIfDivEmpty title h3 div div 我想当 div 为空时隐藏 h3 元素 我愿意更改 html 结构 但 h3 必须位于 div 之外 因为它的内容是动态更改的 有没有办法在 C
  • 您可以从另一个线程访问 UI 元素吗? (未设置)

    我在 google here 上看到很多关于从另一个线程更新 UI 元素的线程 如果我只想获取复选框的值怎么办 我可以做到这一点而不需要做任何特别的事情吗 Edit 看来我得收回之前写的东西了 尝试了以下方法 添加了一个名为的文本框myTe
  • C++ 模板只是伪装的宏吗?

    我已经用 C 编程几年了 并且经常使用 STL 并且多次创建了自己的模板类来看看它是如何完成的 现在 我正在尝试将模板更深入地集成到我的面向对象设计中 一个挥之不去的想法不断浮现在我的脑海中 它们只是一个宏 真的 你可以使用 defines
  • 使用 Terraform 与 A​​zure VM 的 SSH 连接

    我已使用 Terraform 成功创建了一个 VM 作为 Azure 上资源组的一部分 下一步是在新机器中使用 ssh 并运行一些命令 为此 我创建了一个配置程序作为 VM 资源的一部分 并设置了 SSH 连接 resource azure
  • iPhone:显示带有导航栏的模态 UITableViewController

    我正在展示一个模态视图 它是UITableViewController班级 由于某种原因 当我显示导航栏时 它不会显示它 这是我的代码 SettingsCreateAccount detailViewController SettingsC
  • 使用 D3 设置下拉菜单的默认选择

    我创建了一个包含几个月的下拉菜单作为选项 但想预先指定一个选项作为默认值 然而 默认选择似乎顽固地保留在列表中的第一个选项 我尝试了下面的代码 这对我来说很有意义 因为对于任何其他属性 设置一个简单的比较就足以改变该属性的值 var def
  • 在名称为“appServlet”的 DispatcherServlet 中未找到带有 URI [/pms/j_spring_security_check] 的 HTTP 请求的映射

    我开发了一个 Spring 应用程序 并在其中实现了 Spring 安全集成到登录和注销功能 我使用 Spring security 和 xml 配置 但是当我登录系统时 它显示404 控制台告诉我 在名称为 appServlet 的 Di