<!-- 启动SpringMVC的注解功能,它会自动注册HandlerMapping、HandlerAdapter、ExceptionResolver的相关实例 --> <mvc:annotation-driven /> <mvc:default-servlet-handler /> <!-- 启动Spring的组件自动扫描机制 --> <context:component-scan base-package="com.usoft.synusn.controller"></context:component-scan> <!--通用视图解析器 --> <bean id="viewResolverCommon" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/views/" /> <property name="suffix" value=".jsp" /> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="order" value="1" /> </bean>
<!-- SpringMVC的前端控制器 --> <servlet> <servlet-name>spring-mvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <!-- <param-value>classpath*:applicationcontext-webmvc.xml,classpath*:applicationcontext-freemarker.xml</param-value> --> <param-value>classpath*:applicationcontext-web.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring-mvc</servlet-name> <!-- 由SpringMVC拦截所有请求 --> <url-pattern>/</url-pattern> </servlet-mapping>
/** * freemarker控制器 * @author * */ @Controller public class FreeMarkerControler { @RequestMapping("/hello") public String sayHello(ModelMap map) { System.out.println("say Hello ……"); map.addAttribute("message", "Hello World,FreeMarker!"); return "test"; } }
这是我的配置文件和controller,我没发现有什么错误,可总是 No mapping found for HTTP request with URI 改为<url-pattern>/*</url-pattern>试下。 <property name="prefix" value="/WEB-INF/views/" />这里最后又/
@RequestMapping("/hello")//这里就应该是hello,不应该要/了。 应该就一个DispatcherServlet。多视图是要配置多个视图解析器而已吧。还有一个情况啊,我发布我项目后,WEB-INF/class文件夹下是空的,正常吗,这种情况?
|