myeclipse快速搭建springmvc框架

1、打开myeclipse

2、新建工程:点击右键----New----Web Project ,新建一个名为springMvc工程,引入jar包,bulid path.

3、编写web.xml文件


	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
	
	
		index.jsp
	
	
		contextConfigLocation
		
		classpath:spring/spring-base.xml
	
	
		org.springframework.web.context.ContextLoaderListener
	
	
		charsetEncoding
		org.springframework.web.filter.CharacterEncodingFilter
		
			encoding
			UTF-8
		
		
			forceEncoding
			true
		
	
	
		charsetEncoding
		/*
	
	
		dispatcherServlet
		org.springframework.web.servlet.DispatcherServlet
		1
	
	
		dispatcherServlet
		*.action
	

4、新建spring-base.xml文件,根据web.xml文件中路径新建 spring-base.xml文件,在src文件夹下新建spring的package,在该包下新建一个spring-base.xml文件,文件中内容为:

	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

5、新建文件dispatcherServlet-servlet.xml,在WebRoot文件夹下新建 dispatcherServlet-servlet.xml文件,内容如下:







    
        
        
        
        
    
6、接下来新建controller,在src下新建  com.mycontroller的package,在该包下新建MyController.java文件,内容:
package com.mycontroller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/helloworld")
public class Mycontroller {
	@RequestMapping("/hello")
	//即使是只有一个方法,也要写requestMapping注解
 public String hello(){
	 System.out.println("hello world");
		return "/helloworld";
 }
}
7、新建jsp页面,根据 dispatcherServlet-servlet.xml文件中的路径,在WEB-INF文件夹下新建view文件夹,在view文件夹中新建helloworld.jsp文件,内容:
<%@ page language="java" contentType="text/html; charset=UTF8"

    pageEncoding="UTF8"%>









Insert title here





    hello world,gogogo!



8、启动Tomcat,浏览器访问http://localhost:8080/springMvc/helloworld/hello.action




你可能感兴趣的:(springmvc)