在測(cè)試學(xué)習(xí)SpringMVC設(shè)計(jì)模式的時(shí)候偶爾發(fā)現(xiàn)了我的后臺(tái)無法傳值到j(luò)sp頁面中的問題晴弃。找了一晚上沒找到是什么原因,后來在其他人的博客中找到了解決方法,在這里順便記錄一下捻脖。
spring的后臺(tái)代碼
@Controller
@RequestMapping("/test")
public class PersonController {
private PersonService personService;
@Autowired
public void setPersonService(PersonService personService) {
this.personService = personService;
}
@RequestMapping(value = "/person", method = RequestMethod.GET)
public String viewPerson(@RequestParam("num") Integer num, Model model){
System.out.print(num + "\n");
Person person = personService.getPerson();
model.addAttribute("person", person);
return "TestCourseId";
}
}
jsp頁面測(cè)試代碼
<%@ page language="java"
contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!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>測(cè)試CourseId參數(shù)接收和course參數(shù)輸出</title>
</head>
<body>
<h1>測(cè)試Course參數(shù)輸出</h1>
<p>person-age</p><${person.age}><br>
</body>
</html>
沒修改時(shí)的結(jié)果是無法正常輸出的
Paste_Image.png
在jsp頁面中添加下面這行代碼就可以了
<%@ page isELIgnored="false" %>
Paste_Image.png
默認(rèn)EL的忽略是true的锐峭,所以EL是沒法使用的。
希望能幫助到后人可婶。