---
title: "spring_mvc（一）环境搭建"
author: "mistbow"
date: "2011-12-05T18:36:34Z"
tags: []
categories: ["编程语言"]
slug: "spring-mvc"
draft: false
lastmod: "2011-12-05T18:38:24Z"
id: 1292451
url: "https://mistbow.iteye.com/blog/1292451"
---

1\. 建立项目spring\_mvc\_test 2. 引入jar文件，如图： \[img]http://dl.iteye.com/upload/attachment/600387/11f38b2a-4234-36b8-9e83-45279a8da6f0.png\[/img] 3. 下面编辑web.xml文件，配置spring的拦截器： \[code="java"] index.jsp Spring3MVC index.jsp spring org.springframework.web.servlet.DispatcherServlet 1 spring /* \[/code] 4. 配置返回结果的视图spring-servlet.xml： \[code="java"] \[/code] 5.现在可以编写controler代码了： \[code="java"]package net.viralpatel.spring3.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; @Controller public class HelloWorldController { @RequestMapping("simple") public @ResponseBody String helloWorld() { String message = "Hello, this is a simple example"; return message; } }\[/code] 现在在浏览器中输入：http://localhost:8080/spring\_mvc\_test/simple 然后在浏览器中显示Hello, this is a simple example