Azrael-zlf
2016-01-27 10:08关于spring mvc注解的使用,运行tomcat时出错
spring-mvc.xml的代码
<!--开启注解扫描 -->
<context:component-scan base-package="com.tarena"/>
<!--开启MVC注解扫描 -->
<mvc:annotation-driven/>
<!--定义视图解析器ViewResolver -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/"/>
<property name="suffix" value=".jsp"/>
</bean>
页面的代码
package com.tarena.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("/demo")
public class HelloController {
@RequestMapping("/hello.do")
public ModelAndView hello(HttpServletRequest request,
HttpServletResponse response) throws Exception {
System.out.println("Hello, Controller.");
return new ModelAndView("jsp/hello");
}
}
web.xml的代码
springmvc
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:spring-mvc.xml
1
springmvc
*.do
- 点赞
- 回答
- 收藏
- 复制链接分享
7条回答
为你推荐
- SpringMvc使用RequestMapping写helloworld报404,卡了一天了,救救孩子吧
- java
- intellij-idea
- java-ee
- spring
- tomcat
- 1个回答
- 现在是一些关键操作要记录操作日志,但是在insert的时候,偶然会出现插入失败的问题.现在找不到问题所在?
- java
- linux
- spring
- mongodb
- 3个回答
- 哪位大神帮我解决一下eclipse运行突然报404,好像是spring配置文件有问题
- spring
- tomcat
- eclipse
- jar
- java
- 3个回答
- springboot 项目使用mongotemplate 查询mongo数据库,查询字段和Java实体bean不匹配。
- spring
- java
- 2个回答
- mybatis注解开发异常Mapped Statements collection does not contain value
- spring
- java
- 开发语言
- 1个回答
换一换