controller代码
package com.hp.controller; import org.springframework.stereotype.Controller; import org.springframework.validation.Errors; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; @Controller @RequestMapping("/blog") public class BlogController { @RequestMapping("/{id}") public ModelAndView blog(ModelAndView mv,@PathVariable("id") Integer id){ mv.addObject("msg", id); mv.setViewName("blog"); return mv; } }
接受数据的jsp页面
<%@ 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> ${msg} </body> </html>
运行结果如图 EL表达式不起作用
解决办法
一种是在 jsp页面加上这句话
<%@page isELIgnored="false" %>
然后正常显示了.如图