Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何调试一个";未找到HTTP请求的映射";?_Java_Spring_Servlets - Fatal编程技术网

Java 如何调试一个";未找到HTTP请求的映射";?

Java 如何调试一个";未找到HTTP请求的映射";?,java,spring,servlets,Java,Spring,Servlets,我试图用Spring3.0映射一个控制器,但没有成功。我发现以下错误: 2011-07-17 20:01:16536[http-8080-exec-5]WARN org.springframework.web.servlet.PageNotFound-在名为“cp”的DispatcherServlet中找不到URI为[/sherd/cp/index]的http请求的映射 如何调试此错误?我已将日志设置为INFO并看到: 2011-07-17 20:10:28402[main]INFO org.s

我试图用Spring3.0映射一个控制器,但没有成功。我发现以下错误:

2011-07-17 20:01:16536[http-8080-exec-5]WARN org.springframework.web.servlet.PageNotFound-在名为“cp”的DispatcherServlet中找不到URI为[/sherd/cp/index]的http请求的映射

如何调试此错误?我已将日志设置为INFO并看到:

2011-07-17 20:10:28402[main]INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping-将URL路径[/cp/index]映射到处理程序“index”上 2011-07-17 20:10:28402[main]INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping-将URL路径[/cp/index.]映射到处理程序“index”上 2011-07-17 20:10:28402[main]INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping-将URL路径[/cp/index/]映射到处理程序“index”上

但是,我在尝试加载页面时收到上面显示的警告

WEB-INF/WEB.xml的相关部分如下:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/cp-beans.xml</param-value>
</context-param>
<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>
<servlet>
    <servlet-name>cp</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>cp</servlet-name>
    <url-pattern>/cp/*</url-pattern>
</servlet-mapping>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/cp/"/>
    <property name="suffix" value=".jsp"/>
</bean>

我遗漏了什么吗?

我不确定,因为我无法测试,但请尝试更改:

<servlet-mapping>
    <servlet-name>cp</servlet-name>
    <url-pattern>/cp/*</url-pattern>
</servlet-mapping>

内容提供商
/cp/*
为此:

<servlet-mapping>
    <servlet-name>cp</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

内容提供商
/*

RequestMapping注释具有
/cp
,因此应在
servlet映射中省略它

我已设法使其与以下更改一起工作:

@Controller
public class Index {

    @RequestMapping("/index")
    public String show() {
        return "index"; //view 
    }

}
请注意,我已经删除了@RequestMapping和返回的逻辑视图名称中的/cp前缀。另外,在cp-servlet.xml中,我添加了以下内容:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/cp-beans.xml</param-value>
</context-param>
<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>
<servlet>
    <servlet-name>cp</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>cp</servlet-name>
    <url-pattern>/cp/*</url-pattern>
</servlet-mapping>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/cp/"/>
    <property name="suffix" value=".jsp"/>
</bean>

Hi Sangdol,谢谢你的建议。我之所以有前缀,是因为我还有其他servlet映射,我想慢慢迁移。无论如何,为了测试,我尝试了“/*”url模式,也尝试了“/”,但我仍然得到了相同的警告。
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/cp/"/>
    <property name="suffix" value=".jsp"/>
</bean>