@RequestMapping 未正确映射

2023-12-15

我正在尝试设置一个控制器,但不幸的是无法查看输出...一切都正确渲染。当我去http://localhost:8080/CMT/content/edit我收到 404 页面。从 Netbeans 运行我的应用程序会转到http://localhost:8080/CMT

package com.cmt.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class Content {

    @RequestMapping(value="/content/edit", method=RequestMethod.GET)
    public ModelAndView edit(Model model) {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("index");
        return mv;
    }
}

应用程序配置.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    <!-- Scans the classpath of this application for @Components to deploy as beans -->
    <context:component-scan base-package="com.cmt" />
    <!-- Configures the @Controller programming model -->
    <mvc:annotation-driven />
    <!-- Resolves view names to protected .jsp resources within the /WEB-INF/views directory -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp"/>
    </bean>
</beans>

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">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/app-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

我如何调试它并查看哪些有效,哪些无效?

Update

Netbeans 中的 GlassFish 服务器日志显示

INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1531ed: defining beans [content,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0,org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,viewResolver]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@b91162
INFO: Mapped URL path [/content/edit] onto handler [com.cmt.controllers.Content@1f3e27b]
INFO: Mapped URL path [/content/edit.*] onto handler [com.cmt.controllers.Content@1f3e27b]
INFO: Mapped URL path [/content/edit/] onto handler [com.cmt.controllers.Content@1f3e27b]
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: FrameworkServlet 'Spring-MVC-Dispatcher-Servlet': initialization completed in 1234 ms
INFO: WEB0671: Loading application [CMT] at [/CMT]
INFO: CMT was successfully deployed in 3,725 milliseconds.

Is your DispatcherServlet named app映射到/* in web.xml?从你的previous我看到的问题:

<servlet>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/app-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <url-pattern>*.htm</url-pattern>
</servlet-mapping>

/content/edit网址不匹配*.htm图案。尝试/content/edit.htm寻找可能的解决方法。

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

@RequestMapping 未正确映射 的相关文章

随机推荐

  • SyntaxError: 当尝试将对象参数传递给 onclick 函数时,元素列表后缺少 ]

    我正在尝试迭代对象列表 并使用按钮为每个对象创建一个列表项 当我添加onclick对他们起作用 我收到这个错误 语法错误 元素列表后缺少 这是我的代码 box resources forEach function box box resou
  • 遗传算法中的轮盘选择

    谁能提供一些轮盘赌选择函数的伪代码 我将如何实现这个 我真的不明白如何阅读这个数学符号 我从来没有做过任何概率或统计数据 我自己这样做已经有几年了 但是在谷歌上很容易找到以下伪代码 for all members of population
  • Bash 参数扩展

    我有一个使用以下逻辑的脚本 if z 1 then if any parameter is supplied ACTION clear ACTION else ACTION echo otherwise set it to echo fi
  • 合并两个不同长度的python pandas数据帧+求和公共值

    我有以下问题 我有两个不同长度的 pandas 数据帧 其中包含一些具有共同值的行和一些不同的行 如下所示 df1 s1 s2 s3 s4 sp1 1 0 1 1 sp2 1 1 0 1 sp3 1 1 1 0 sp4 1 1 1 1 df
  • 模拟“如果不存在则创建用户”的语法错误

    MySQL 不允许您指定if not exists中的条款create user声明 尽管事实上create table and create procedure支持这一点 2005 年曾有一个对此的功能请求 但 MySQL 开发人员已经对
  • 使用 MySQLi 的 real_escape_string 作为静态函数

    我想知道是否可以转义字符串 使用 real escape string 而无需先创建对象实例来应用该函数 即 我们可以这样做 database new mysqli DB HOST DB USER DB PASS DB NAME datab
  • 限制在 PDF 页面边界内移动/拖动 pdf 注释

    我正在使用 PDF 套件库在 PDF 视图上加载一份 PDF 我在 pdf 视图上添加了一个自定义视图 与 PDF 注释相同 并且允许用户使用 UIPanGestureRecognizer 在 pdf 视图上 在 pdf 视图 容器视图内
  • 如何在MSVC中有效地将两个__m128d转换为一个__m128i?

    转换然后移位然后按位或是从两个转换的唯一方法 m128d到一个单一的 m128i 这对于 x64 构建中的 Xcode 来说是完全可以接受的 m128d v2dHi m128d v2dLo m128i v4i mm set epi64 mm
  • 如何杀死 C# 线程?

    我有一个线程在我们的 旧 SQL 服务器上查找数据 当数据进入时 我将信息发布到模式对话框中 在所有这些处理正在进行时 用户不能也不应该做任何其他事情 模式对话框只是让他们看到我正在做某事并防止他们同时运行另一个查询 有时 很少 当代码调用
  • 如何在 vi 搜索和替换中包含正斜杠

    我有一个包含字符串的文件usrbin 我想寻找usrbin并将其替换为 usr bin I tried s usrbin usr bin g 但它显示错误E488 Trailing characters 如何在搜索和替换中包含正斜杠 这里有
  • Enterprise Library 6 验证配置文件

    我正在尝试学习 EnterpriseLibraryValidatoin 当我配置 TypeValidation 通过配置文件验证类时 它不会拾取 但是当我添加数据注释时它会正确验证 我不知道我是否遗漏了一些东西 请提供任何帮助 验证配置文件
  • JS:仅过滤非空和字符串值类型的数组

    我正在尝试过滤这样的数组 array filter e gt return e 有了这个我想过滤所有空字符串 包括undefined and null 不幸的是 我的数组有一些不应该存在的数组 因此 我还需要仅检查字符串值并删除所有其他值
  • 通俗地说,Ruby 自我?

    Ruby self 什么时候引用 Object 什么时候 self 引用 Ruby 类 带有示例的解释会很棒 我不明白这个问题 类本身就是对象 假设我有一堂课Person 这实际上是一个实例Class 所以你可以让 self 引用 Arti
  • 在 Javascript 中将数字连接为字符串

    myCoolObject a 0 b 12 c 24 我想串联a b and c使它们看起来像一个唯一的字符串 a b c 或示例中的 0 12 24 a b and c总是代表数字 将它们中的每一个从 int 转换为 string 需要大
  • 未找到整数 parseInt 方法

    我正在尝试在这段代码中测试一个简单的方法 您在其中使用接收参数的方法 正在发生的问题是Integer解析 int 方法 命令提示符给出的错误是 java 24 error cannot find symbol cholo Integer p
  • 清除 QGraphicsScene 中的小部件:崩溃

    我有一个 QGraphicsScene 里面有一个 QPushButton 清除这个场景将使我的应用程序崩溃 有没有正确的方法来使用 QWidget 清除场景 单击按钮时以下代码会崩溃 include
  • python:multiprocessing.Pipe 和重定向标准输出

    我在用multiprocessing包生成第二个进程 我想将 stdout 和 stderr 重定向到第一个进程 我在用multiprocessing Pipe object dup2 output pipe fileno 1 Where
  • VS 2010 Ultimate:将 ProteusDebugEngine 调试器附加到进程失败

    当将 C NET 4 项目加载到我的主机 Win 7 Ultimate 64 位 上的 VS 2010 Ultimate 中时 我收到错误消息 Attaching the ProteusDebugEngine debugger to pro
  • 使用“.gitattributes”文件修复 Git 存储库中的行结尾

    需要修复什么 我有一个包含单个 md文件 其中包含我正在写的一篇文章 我在几台不同的计算机上编辑该文件 其中一台运行 Linux 另一台运行 Windows 看着一个git diff现在在 Windows 中我做了一些更改 我可以看到我的文
  • @RequestMapping 未正确映射

    我正在尝试设置一个控制器 但不幸的是无法查看输出 一切都正确渲染 当我去http localhost 8080 CMT content edit我收到 404 页面 从 Netbeans 运行我的应用程序会转到http localhost