使用最新springframework 4.2.3.RELEASE + Maven 3.3.9 + eclipse(Mars.1 Release (4.5.1)) 搭建IM平台(一)

关于开发环境的搭建,在这里不会描述和讲解。You can use google or yahoo search how to build development environment.

直接上源码


No.1 pom.xml file.


	4.0.0
	wlife
	im
	war
	0.0.1-SNAPSHOT
	im Maven Webapp
	http://maven.apache.org
	
	
		4.2.3.RELEASE
		5.1.38
		3.8.1
		1.2
		1.1.2
	
	
		
		
			org.springframework
			spring-core
			${spring.version}
		
		
			org.springframework
			spring-webmvc
			${spring.version}
		
		
			org.springframework
			spring-web
			${spring.version}
		
		
			org.springframework
			spring-jdbc
			${spring.version}
		
		
			org.springframework
			spring-tx
			${spring.version}
		
		

		
		
			junit
			junit
			${junit.version}
			test
		
		

		
		
			jstl
			jstl
			${jstl.version}
		
		
			taglibs
			standard
			${taglibs.version}
		
		

		
		
			mysql
			mysql-connector-java
			${mysql.version}
		
		
	
	
		im
	


No.2 web.xml file.




	Archetype Created Web Application
	
		contextConfigLocation
		classpath:/spring/spring-*.xml
	

	
		CharacterEncodingFilter
		org.springframework.web.filter.CharacterEncodingFilter
		
			encoding
			utf-8
		
	
	
		CharacterEncodingFilter
		/*
	

	
		
			org.springframework.web.context.ContextLoaderListener
		
	

	
		dispatcher
		
			org.springframework.web.servlet.DispatcherServlet
		
		
			
			contextConfigLocation
			classpath:/spring/dispatcher-servlet.xml
		
		1
	

	
		dispatcher
		/
	

	
	
		404
		/WEB-INF/pages/404.jsp
	
	
		500
		/WEB-INF/pages/500.jsp
	


No.3 dispatcher-servlet.xml file.



	
	
	

	
	
	
	

	
	
		
			/WEB-INF/views/
		
		
			.jsp
		
	


No.4 HelloController.java file.
package com.wlife.im.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class HelloController {

	@RequestMapping("/index")
	public String index(@RequestParam(value = "username", required = false) String username,
			@RequestParam(value = "age", required = false) String age, Model model) {
		Map map = new HashMap();
		map.put("username", username);
		map.put("age", age);
		model.addAllAttributes(map);
		return "index";
	}

	@RequestMapping("/hello")
	public String welcomeMessage(@RequestParam(value = "username", required = false, defaultValue = "") String username,
			@RequestParam(value = "age", required = false, defaultValue = "") String age, Model model) {
		Map map = new HashMap();
		map.put("username", username);
		map.put("age", age);
		model.addAllAttributes(map);
		if (!username.equals("") && !age.equals("")) {
			return "hello";
		} else {
			return "redirect:index";
		}
	}
}

运行截图:
使用最新springframework 4.2.3.RELEASE + Maven 3.3.9 + eclipse(Mars.1 Release (4.5.1)) 搭建IM平台(一)_第1张图片使用最新springframework 4.2.3.RELEASE + Maven 3.3.9 + eclipse(Mars.1 Release (4.5.1)) 搭建IM平台(一)_第2张图片使用最新springframework 4.2.3.RELEASE + Maven 3.3.9 + eclipse(Mars.1 Release (4.5.1)) 搭建IM平台(一)_第3张图片

if you need source code,please contact me.
QQ:2279117256

你可能感兴趣的:(web)