ItemsController.java
@Controller
public class ItemsController {
// 商品查询列表
@RequestMapping("/queryItems")
public ModelAndView queryItems() throws Exception {
//调用service查找 数据库,查询商品列表,这里使用静态数据模拟
List<Items> itemsList = new ArrayList<Items>();
//向list中填充静态数据
Items items_1 = new Items();
items_1.setName("联想笔记本");
items_1.setPrice(6000f);
items_1.setDetail("ThinkPad T430 联想笔记本电脑!");
Items items_2 = new Items();
items_2.setName("苹果手机");
items_2.setPrice(5000f);
items_2.setDetail("iphone6苹果手机!");
itemsList.add(items_1);
itemsList.add(items_2);
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("itemsList", itemsList);
// 指定视图
modelAndView.setViewName("/WEB-INF/jsp/items/itemsList.jsp");
System.out.println(items_1.name);
System.out.println(modelAndView);
return modelAndView;
}
}
itemsList.jsp
<c:forEach items="${itemsList}" var="item">
<tr>
<td>${item.name }</td>
<td>${item.price }</td>
<%-- <td><fmt:formatDate value="${item.createtime}" pattern="yyyy-MM-dd HH:mm:ss"/></td> --%>
<td>${item.detail }</td>
<td><a href="${pageContext.request.contextPath }/item/editItem.action?id=${item.id}">修改</a></td>
</tr>
</c:forEach>
spring-servlet.xml
<context:component-scan base-package="cn.itcast.ssm.controller"></context:component-scan>
<!--注解映射器 -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
<!--注解适配器 -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>
<!-- 使用 mvc:annotation-driven代替上边注解映射器和注解适配器配置
<!-- <mvc:annotation-driven></mvc:annotation-driven> -->
<!-- 视图解析器 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 配置jsp路径的前缀 -->
<!-- <property name="prefix" value="/WEB-INF/jsp"/> -->
<!-- 配置jsp路径的后缀 -->
<!-- <property name="suffix" value=".jsp"/> -->
</bean>
web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<!-- springmvc前端控制器 -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- contextConfigLocation配置springmvc加载的配置文件(配置处理器映射器,适配器) -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
</web-app>
debug的时候数据是有的,modelAndView我也返回了,但是页面却显示
不知道这是什么原因?
这是el表达式无法解析的问题。
1.Application server in question doesn't support JSP 2.0. (应用服务器不支持JSP2.0)
2.The web.xml is not declared as Servlet 2.4 or higher. (web.xml中servlet版本没有声明在2.4以上)
3.The @page is configured with isELIgnored=true. (页面上配置了<%@ page isELIgnored="true" %> )
4.The web.xml is configured with <el-ignored>true</el-ignored> in <jsp-config>. (web.xml中显式地配置了忽略EL表达式)