2 zymx14 zymx14 于 2016.03.08 22:25 提问

请教下关于springmvc简单例子出错问题

警告: No mapping found for HTTP request with URI [/springmvc4/test1/helloworld] in DispatcherServlet with name 'springmvc'
运行后一直报错。
我贴下代码 各位帮我看下
web配置:
<?xml version="1.0" encoding="UTF-8"?>

springMVC1

index.html
index.htm
index.jsp
default.html
default.htm
default.jsp

spring-servlet.xml配置

springmvc
org.springframework.web.servlet.DispatcherServlet

contextConfigLocation
classpath*:config/spring-servlet.xml

1


springmvc
/


<?xml version="1.0" encoding="UTF-8"?>
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

 <bean name="/test1/helloworld" class="com.web.controller.HelloWorldController" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/"></property>
    <property name="suffix" value=".jsp"></property>
</bean>

 com.web.controller下的类:

package com.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
public class HelloWorldController implements Controller{
public ModelAndView handleRequest(HttpServletRequest arg0,
HttpServletResponse arg1) throws Exception {
System.out.println("aasdadasd");

    return new ModelAndView("/welcome");
}

}


4个回答

rui888
rui888   Ds   Rxr 2016.03.09 09:47
已采纳

你 /springmvc4/test1/helloworld
这个对应的url 找不到你的controller 中的方法 ,看看是否扫描到相应的controller

Royal_lr
Royal_lr   Ds   Rxr 2016.03.09 11:45

你的路径都没配置的,,,

a15995111a
a15995111a   2016.03.11 10:47

uri:/springmvc4/test1/helloworld,映射到方法时方法上应该配置@RequestMapping吧

xzchaoo
xzchaoo   2016.03.11 14:00

建议直接写注解吧, xml太麻烦了

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!