环境准备 >>>>>>java JDK和tomcat,eclipse
1.创建项目
2.项目名称自定义,这边为demo
3.我们已经创建完一个动态网站的项目,还得下载Spring MVC相关的jar包,Spring MVC有很多版本,下面提供的是3.2.8的版本,如果需要其他不同版本,自行网上搜索下载,或者到官网
下载解压
将里面的jar包,粘贴到 >>>>>> E:\eclipse-workplace\demo\WebContent\WEB-INF\lib这是我项目路径
commons-loging的http://mirrors.tuna.tsinghua.edu.cn/apache//commons/logging/binaries/commons-logging-1.2-bin.zip用来记录程序运行的日志活动。下载完,将commons-loggin-1.2.jar和commons-logging-1.2-javadoc.jar复制到项目的lib文件夹下。
4.还需要对项目配置server
5.然后配置站点文件web.xml
web.xml是用来初始化配置信息的,如welcome页面,listener等
配置web.xml信息
Spring MVC DEOM
springMVC
characterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
forceEncoding
true
characterEncodingFilter
/*
SpringMVC-DEOM
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
/WEB-INF/applicationContext.xml
1
SpringMVC-DEOM
/
6.Spring MVC配置文件applicationContext.xml,就是spring的配置信息,要实现什么都是通过配置文件来实现的<?xml version="1.0" encoding="UTF-8"?>
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd">
applicationContext.xml配置
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd">
id:确定该Bean的唯一标识符,容器对Bean管理、访问、以及该Bean的依赖关系,都通过该属性完成。Bean的id属性在Spring 配置文件中是唯一的。
class:指定该Bean的具体实现类。注意这里不能使接口。通常情况下,Spring会直接使用new关键字创建该Bean的实例,因此,这里必须提供Bean实现类的类名。
6.Java Resource -> src上 右键点击-> new ->package 建立com.test.controller 建立一个包,之后在这个包上右键点击new->class ,类名为HelloWorld,之后点击Finish.
7.HelloWorld.java代码为
7.然后测试访问