简单的Spring MVC 程序 原

package group.esperanto.action;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
// 定义该Action的映射路径
// 该路径绝对不能重复
@RequestMapping("/pages/emp/*")
public class EmpAction {	
	private	Logger log = Logger.getLogger(EmpAction.class);
	
	@RequestMapping("echo")  //映射方法名
   public void echo(String msg){
	   Logger.getLogger(EmpAction.class).info(msg);
   }
	@RequestMapping("list")
   public ModelAndView list(    // 设置参数亲求名和 默认值
			   @RequestParam(value="cp",defaultValue="1") int currentPage,
			   @RequestParam(value="lc",defaultValue="10") int lineSize,
			   @RequestParam(value="col",defaultValue="title") String column,
			   @RequestParam(value="kw",defaultValue="") String keyWord){
		     log.info("--- currentPage : "+currentPage+" ---");
		     log.info("--- lineSize : "+lineSize+" ---");
		     log.info("--- column : "+column+" ---");
		     log.info("--- keyWord : "+keyWord+" ---");		
		     return null;
	 }
	@RequestMapping("get")    // 接收Servlet内置对象 request,response
   public ModelAndView get(int id,HttpServletRequest request,HttpServletResponse response){
	   HttpSession session = request.getSession();
	   ServletContext application = request.getServletContext();
	   log.info("--- contextPath :" + request.getServletPath());
	   log.info("--- sessionId :" + session.getId());
	   log.info("--- realPath :" + application.getRealPath("/"));
	   try {
		    response.getWriter().println("Hello Spring MVC");
	    } catch (IOException e) {
		    e.printStackTrace();
	    }
	   return null;
   }	
}

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏一个会写诗的程序员的博客

On the Rise of Kotlin

It’s rare when a highly structured language with fairly strict syntax sparks emo...

8520
来自专栏Netkiller

Spring boot with Oracle

本文节选自《Netkiller Java 手札》 地址: http://www.netkiller.cn/java/index.html 9.11. Sprin...

33140
来自专栏Netkiller

Phalcon VS Spring 用法对照手册

Phalcon VS Spring 摘要 Phalcon VS Spring 用法对照表 ---- 目录 1. Install 1.1. Phalcon 1.2...

44060
来自专栏Netkiller

String boot with Apache kafka 完整的发布订阅例子

本文节选自电子书《Netkiller Java 手札》地址 http://www.netkiller.cn/ 5.21.7. 完整的发布订阅实例 上面的例子仅仅...

38360
来自专栏ml

HDUOJ------3336 Count the string(kmp)

D - Count the string Time Limit:1000MS     Memory Limit:32768KB     64bit IO F...

30360
来自专栏ml

hdu----(3118)Arbiter(构造二分图)

Arbiter Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K ...

34550
来自专栏ml

暑假集训之专题----拓扑排序题解

第一单: Problem A Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/3276...

31150
来自专栏Netkiller

Spring Data MongoDB

以下节选自《Netkiller Java 手札》 11.6.2. Spring Data MongoDB 11.6.2.1. pom.xml 注意Spring4...

37150
来自专栏用户2442861的专栏

python format 使用 技巧

Simple positional formatting is probably the most common use-case. Use it if the...

47120
来自专栏算法修养

HOJ 2139 Spiderman's workout(动态规划)

Spiderman’s workout My Tags (Edit) Source : Nordic Collegiate Programming ...

34060

扫码关注云+社区

领取腾讯云代金券