在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java/ JSP頁面數(shù)據(jù)不能載入

JSP頁面數(shù)據(jù)不能載入

ItemsController.java

@Controller
public class ItemsController {
    
    // 商品查詢列表
    @RequestMapping("/queryItems")
    public ModelAndView queryItems() throws Exception {
        
        //調(diào)用service查找 數(shù)據(jù)庫,查詢商品列表,這里使用靜態(tài)數(shù)據(jù)模擬
        List<Items> itemsList = new ArrayList<Items>();
        //向list中填充靜態(tài)數(shù)據(jù)
        
        Items items_1 = new Items();
        items_1.setName("聯(lián)想筆記本");
        items_1.setPrice(6000f);
        items_1.setDetail("ThinkPad T430 聯(lián)想筆記本電腦!");
        
        Items items_2 = new Items();
        items_2.setName("蘋果手機(jī)");
        items_2.setPrice(5000f);
        items_2.setDetail("iphone6蘋果手機(jī)!");
        
        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>

clipboard.png
debug的時(shí)候數(shù)據(jù)是有的,modelAndView我也返回了,但是頁面卻顯示

clipboard.png

不知道這是什么原因?

回答
編輯回答
呆萌傻

web app 節(jié)點(diǎn)改成這樣

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

</web-app>
2017年7月23日 09:46
編輯回答
做不到

這是el表達(dá)式無法解析的問題。
1.Application server in question doesn't support JSP 2.0. (應(yīng)用服務(wù)器不支持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表達(dá)式)

2017年5月5日 14:38
編輯回答
兮顏

這問題好像是沒有解析數(shù)據(jù),后臺無法傳對象到前臺

2017年8月15日 08:52
編輯回答
涼薄
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

注解驅(qū)動(dòng)打開

  <!-- 擴(kuò)充了注解驅(qū)動(dòng),可以將請求參數(shù)綁定到控制器參數(shù) -->
   <mvc:annotation-driven />
<mvc:annotation-driven
/>提供了:數(shù)據(jù)綁定支持,@NumberFormatannotation支持,@DateTimeFormat支持,@Valid支持,讀寫XML的支持(JAXB,讀寫JSON的支持(Jackson)。我們處理響應(yīng)ajax請求時(shí),就使用到了對json的支持(配置之后,在加入了jackson的core和mapper包之后,不寫配置文件也能自動(dòng)轉(zhuǎn)換成json)。

有異常日志嗎?

2018年2月10日 12:19