一步一步学习springmvc之一:基本环境的搭建
2013-05-13 13:32
239 查看
1、在eclipse中创建一个动态的webapp
2、WEB-INF/lib导入需要的jar文件
spring.jar (from spring-framework-2.5/dist)
spring-webmvc.jar(from spring-framework-2.5/dist/modules)
commons-logging.jar (from spring-framework-2.5/lib/jakarta-commons)
3、配置web.xml
4.springapp-servlet.xml
5、创建一个控制器
6、然后在WebContent目录下创建一个hello.jsp
6、启动tomcat在浏览器中输入:http://localhost:8080/springmvc/hello.htm即可
2、WEB-INF/lib导入需要的jar文件
spring.jar (from spring-framework-2.5/dist)
spring-webmvc.jar(from spring-framework-2.5/dist/modules)
commons-logging.jar (from spring-framework-2.5/lib/jakarta-commons)
3、配置web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app 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"> <!-- 映射的配置 --> <servlet> <servlet-name>springapp</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <!-- 將所有以*.htm結尾的请求交给 org.springframework.web.servlet.DispatcherServlet--> <servlet-mapping> <servlet-name>springapp</servlet-name> <url-pattern>*.htm</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file> index.jsp </welcome-file> </welcome-file-list> </web-app>
4.springapp-servlet.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" 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-2.5.xsd"> <!-- 配置DispatcherServlet --> <!-- /hello.htm的请求交给 springapp.web.HelloController--> <bean name="/hello.htm" class="springapp.web.HelloController"/> </beans>
5、创建一个控制器
package springapp.web; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; public class HelloController implements Controller { @Override public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { return new ModelAndView("hello.jsp"); } }
6、然后在WebContent目录下创建一个hello.jsp
<%@ page language="java" contentType="text/html; charset=gbk" pageEncoding="gbk"%> <!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=gbk"> <title>Insert title here</title> </head> <body> <h1>Hello - Spring Application</h1> <p>Greetings.</p> </body> </html>
6、启动tomcat在浏览器中输入:http://localhost:8080/springmvc/hello.htm即可
相关文章推荐
- Spring 、SpringMVC、Mybatis、MySQL、Maven、Tomcat搭建JavaWeb项目流程---学习笔记(一)工具准备及环境配置
- 【JAVAWEB学习笔记】springmvc环境搭建
- SpringMvc学习-环境搭建
- 【JavaEE学习笔记】SpringMVC_01_快速搭建一个环境,简介,常用方法
- 一步一步学习androidNDK编程(搭建开发环境)
- hadoop学习准备环境:ubuntu学习笔记-基本环境的搭建
- 一步一步学习ASP.NET 5 (一)-基本概念和环境配置
- Grunt学习笔记之开发环境的搭建与创建一个基本的项目
- SpringMVC学习之环境搭建踩坑总结(二)
- SpringMVC学习(一)环境搭建以及HelloWorld
- Nutch1.7学习笔记:基本环境搭建及使用
- SpringMVC学习-->第一天-搭建开发环境
- (转) 一步一步学习ASP.NET 5 (一)- 基本概念和环境配置
- 开始hadoop前的准备:ubuntu学习笔记-基本环境的搭建(ssh的安装,SecureCRT连接,vim的安装及使用、jdk的安装)
- 一步一步学习struts2(1):搭建struts2开发环境
- SpringMVC入门学习(一) 环境搭建+实例演示
- SpringMVC学习使用一:搭建简单的SpringMVC开发项目环境并使用
- Nutch1.7学习笔记1:基本环境搭建及使用
- Nutch1.7学习笔记:基本环境搭建及使用
- Nutch1.7学习笔记1:基本环境搭建及使用