直接上图吧:

jar包:

项目文件夹一览:

这里的HelloWeb-servlet,xml 是在WEB-INF 下

HelloController:

package com.cqu.tutorial;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; @Controller
@RequestMapping("/hello")
public class HelloController {
@RequestMapping(method=RequestMethod.GET)
public String printHello(ModelMap model){
model.addAttribute("message","Hello Spring mvc");
return "hello";
}
}

在WEB-INF 下建立web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>Spring MVC Application</display-name> <servlet>
<servlet-name>HelloWeb</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>HelloWeb</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

这里要注意<url-pattern> 要是"/“ ,之前我用”*.jsp“ 它会提示找不到mapping的路径

然后在同级文件夹下建立HelloWeb-servlet.xml  这里的HelloWorld 一定要和web里面的servlet-name相应

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
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.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd"> <context:component-scan base-package="com.cqu.tutorial"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/hello/" />
<property name="suffix" value=".jsp" />
</bean> </beans>

最后在WEB-INF 下建一个目录 hello ,而且创建hello.jsp文件:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello Spring MVC</title>
</head>
<body>
<h2>${message}</h2>
</body>
</html>

然后执行,http://localhost:8080/HelloSpring  这样是不会有东西的,自己加入/hello 就能够了:http://localhost:8080/HelloSpring/hello

Spring3.2 HelloWorld的更多相关文章

  1. Spring中Bean的命名问题(id和name区别)及ref和idref之间的区别

    Spring中Bean的命名 1.每个Bean可以有一个id属性,并可以根据该id在IoC容器中查找该Bean,该id属性值必须在IoC容器中唯一: 2.可以不指定id属性,只指定全限定类名,如: & ...

  2. (转)Spring中Bean的命名问题(id和name区别)及ref和idref之间的区别

    Spring中Bean的命名 1.每个Bean可以有一个id属性,并可以根据该id在IoC容器中查找该Bean,该id属性值必须在IoC容器中唯一: 2.可以不指定id属性,只指定全限定类名,如: & ...

  3. Spring中Bean的命名问题及ref和idref之间的区别

    一直在用Spring,其实对其了解甚少,刚去了解了一下Spring中Bean的命名问题以及ref和idref之间的区别,略作记录,以备后查. Spring中Bean的命名 1.每个Bean可以有一个i ...

  4. Spring Framework5.0 学习(4)—— Bean的命名id和name区别

    Spring中Bean的命名 1.每个Bean可以有一个id属性,并可以根据该id在IoC容器中查找该Bean,该id属性值必须在IoC容器中唯一: 2.可以不指定id属性,只指定全限定类名,如: & ...

  5. Bean的id、name、ref、refid

    Spring中Bean的命名 1.每个Bean可以有一个id属性,并可以根据该id在IoC容器中查找该Bean,该id属性值必须在IoC容器中唯一: 2.可以不指定id属性,只指定全限定类名,如: & ...

  6. Spring_One

    Spring_01 Spring概述 Spring是分层的Java2E应用full-stack轻量级开源框架,,以IoC(Inverse Of Control:反转控制)和AOP(Aspect Ori ...

  7. Eclipse中Maven+Spring3.2.8+SpringMVC HelloWorld项目

    本文适合有一定spring和springmvc基础,并想使用Maven管理项目的人. 源码打包:http://pan.baidu.com/s/1hqurUcs 转载请声明出处(http://www.c ...

  8. 用Spring3编写第一个HelloWorld项目

    第一个HelloWorld程序 让我们用Spring来写第一个应用程序吧. 完成这一章要求: 熟悉Java语言 设置好Spring的环境 熟悉简单的Eclipse IDE的操作 如果你还没有设置好环境 ...

  9. spring3: AOP 之 6.2 AOP的HelloWorld

    6.2.1  准备环境 首先准备开发需要的jar包,请到spring-framework-3.0.5.RELEASE-dependencies.zip和spring-framework-3.0.5.R ...

随机推荐

  1. sql2005,sql2008,sql2012清空日志语句

    原文:sql2005,sql2008,sql2012清空日志语句 sql2005清空日志语句 Backup Log DbName WITH no_log GO DUMP TRANSACTION DbN ...

  2. 谨记给UpdatePanel中动态添加的控件赋ID

    原文:谨记给UpdatePanel中动态添加的控件赋ID 昨天下定决 心对上次做的布局编辑器控件加以改进,其中最主要变化的就是要完全使用ASP.NET AJAX!但是很遗憾,虽然耳闻已久,但目前对AS ...

  3. Java使用反射机制优化工厂方法

    我先举个例子,有一个接口People,这个接口有一个方法: package com.wjy.reflect; public interface People { public abstract voi ...

  4. hunnu-11546--Sum of f(x)

    Sum of f(x) Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB Total submit users:  ...

  5. ie6下margin双倍距的问题

    今天中午休息时, 公司客服突然报出来一个bug, 一个用ie6的用户打开我们活动网站时, 发现内容都错乱了, 我赶紧上线一看, 发现是正常的. 找了台ie6的xp机器再看了下, 重现出了这个用户的问题 ...

  6. Sqlite 扩展功能 GET_PHONEBOOK_INDEX

    在联系人数据库设计中遇到了这个函数,晚上找了半天没找到答案. GET_PHONEBOOK_INDEX This function will produce a normalized upper cas ...

  7. Android ImageButton Example 图片按钮

    Android ImageButton Example 图片按钮 使用“android.widget.ImageButton” 展现一个具有背景图片的按钮 本教程将展现一个具有名字为 c.png背景图 ...

  8. 原创教程“ActionScript3.0游戏中的图像编程”開始连载啦!

            经过近两年的不懈努力,笔者的原创教程"ActionScript3游戏中的图像编程"最终在今日划上了完美的句号!这其中记录着笔者多年来在游戏制作,尤其是其中图像处理方 ...

  9. Android开发工具综述,开发人员必备工具

    安卓开发工具汇总.开发者必备.安卓开发过程中须要用到各种工具,作为一名安卓开发者,有木有感到亚历山大,那么多工具! 今天给大家汇总了一下安卓开发工具,安卓开发者必备利器. 1.Draw 9-Patch ...

  10. Linux 该文件命令查看内容

    Linux系统,请使用以下命令来查看文件的内容: cat tac  从最后一行開始显示.能够看出 tac 是 cat 的倒著写! nl   显示的时候,顺道输出行号! more 一页一页的显示文件内容 ...