package com.lmz.controller;
import java.text.SimpleDateFormat;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("welcome")
public class HelloWordController {
@RequestMapping(value="printWelcome")
public String printWelcome(ModelMap model) {
model.addAttribute("message", "Spring3 MVC");
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
model.addAttribute("date", dateFormat.format(new java.util.Date()));
return "hello";
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>Message:${message}</h1>
<h2>当前时间:${date}</h2>
</body>
</html>
Message:${message}
当前时间:${date}
导致的原因是jsp中 EL默认为true,默认是忽略的,加上下面红色字体就可以正常显示了:
<%@ page isELIgnored="false" language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>Message:${message}</h1>
<h2>当前时间:${date}</h2>
</body>
</html>