我的context.xml是这样:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
controller的方法是:
@RequestMapping(method = RequestMethod.GET)
public ModelAndView index(HttpServletRequest request, HttpServletResponse response) {
ModelAndView modelAndView = new ModelAndView("home");
modelAndView.addObject("appTitle", "hello");
return modelAndView;
}
视图home.js是:
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html>
<head>
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
</head>
<body>
${appTitle}
</body>
</html>
为什么在显示时,直接把:${appTitle}这一串字显示出来了,而不是显示的我在controller中设置给appTitle的值:modelAndView.addObject("appTitle", "hello");