手动配置springMVC4的方法

手动配置springMVC4的方法

一开始网上查了N多文章都是拿maven 装的,而且配置文件都一堆一堆的特别乱,不容易让人明白,所以这里提供一个最基本的HELLO WORLD

创建一个动态的WEB工程 Dnamic Web Probject

导入如下包
commons-logging-1.1.3.jar
spring-aop-4.0.0.RELEASE.jar
spring-beans-4.0.0.RELEASE.jar
spring-context-4.0.0.RELEASE.jar
spring-core-4.0.0.RELEASE.jar
spring-expression-4.0.0.RELEASE.jar
spring-web-4.0.0.RELEASE.jar
spring-webmvc-4.0.0.RELEASE.jar


在WEB.XML 中添加如下内容


  
	
		springDispatcherServlet
		org.springframework.web.servlet.DispatcherServlet
		
			contextConfigLocation
			classpath:springmvc.xml
		
		1
	

	
	
		springDispatcherServlet
		/
	
  

在 src 目录下创建
springmvc.xml



	
	

	
	
		
		
	

创建一个测试HelloWorld.java
package cn.jgls.springmvc.handlers;

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

@Controller
public class HelloWorld {
	
	@RequestMapping("/helloworld")
	public String hello(){
		System.out.println("hello world");
		return "success";
	}
}

在web下创建一个 index.jsp的页面
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>




Insert title here


	helloworld



运行程序,就完成了一个 最基本的 Hello World 了!!

你可能感兴趣的:(java,java,springMVC4,springMVC)