rt,刚学springmvc想试一下,然后。。。我的配置文件:mvc-dispatcher-servlet.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.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.xsd"> <context:annotation-config></context:annotation-config> <!--指明 controller 所在包,并扫描其中的注解--> <context:component-scan base-package="com.lzq.zsk"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"></context:include-filter> </context:component-scan> <!-- 静态资源(js、image等)的访问 --> <mvc:default-servlet-handler/> <!-- 开启注解 --> <mvc:annotation-driven></mvc:annotation-driven> <!--ViewResolver 视图解析器--> <!--用于支持Servlet、JSP视图解析--> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property> <property name="prefix" value="/WEB-INF/pages/"></property> <property name="suffix" value=".jsp"></property> </bean></beans> MainController.java package com.lzq.zsk.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;@Controller@RequestMapping("/hello")public class MainController { @RequestMapping("/mvc") public String helloMVC(){ System.out.println("helo"); return "home"; }}
7 回答

aluckdog
TA贡献1847条经验 获得超7个赞
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
web.xml少了上面这句,把Spring容器集成到 Web 应用里面
添加回答
举报
0/150
提交
取消