tabe上没有打印数据

时间:2016-12-22 12:04:36

标签: java spring jsp spring-mvc

表中未打印数据

Bean类名称是地址,user_id_fk在会话

的帮助下检索user_id
@RequestMapping("/address")

public ModelAndView address(HttpServletRequest request , HttpServletResponse response ,ModelAndView modelAndView){
        HttpSession session=request.getSession();   
        String user_id_fk = (String)session.getAttribute("user_id");

          UMService a = new UMserviceimp();
          address ad=new address();
          ad.setUser_id_fk(Integer.parseInt(user_id_fk));
          ad=a.addr(ad);

          modelAndView.addObject("studentbean",ad);
          modelAndView.setViewName("address");
           return modelAndView;

    }

当我们使用它时,数据将打印到控制台:

          System.out.println("address" +ad.getUser_id_fk());
          System.out.println("line_1"+ad.getLine_1());
          System.out.println("line_2"+ad.getLine_2());
          System.out.println("line_3"+ad.getLine_3());
          System.out.println("city"+ad.getCity());
          System.out.println("state"+ad.getState());
          System.out.println("pincode"+ad.getPin_code());
          System.out.println("country"+ad.getCountry());
          System.out.println("address_type"+ad.getAddress_type());



<!--address.jsp-->
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding``="ISO-8859-1"%>

    <%@page import="com.cms.org.um.bean.address"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 

    <!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=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>

    <table border="1" align="left">
    <tr>
    <th>line_1</th>
    <th>line_2</th>
    <th>line_3</th>
    <th>city</th>
    <th>state</th>
    <th>country</th>
    <th>pin_code</th>
    <th>address_type</th>
    </tr>

    <c:forEach items="${studentbean}" var="u">
    <tr>
    <td>${u.line_1}</td>
    <td>${u.line_2}</td>
    <td>${u.line_3}</td>
    <td>${u.city}</td>
    <td>${u.state}</td>
    <td>${u.country}</td>
    <td>${u.pin_code}</td>
    <td>${u.address_type}</td>
    </tr>
    </c:forEach>
    </table>
    </body>
    </html>

<!-- end snippet -->

1 个答案:

答案 0 :(得分:0)

从对象获取字段值&#34; u&#34;你必须做这样的事情:

<c:forEach items="${studentbean}" var="u">
<tr>
<td><%${u.line_1}%></td>
<td><%${u.line_2}%></td>
<td><%${u.line_3}%></td>
<td><%${u.city}%></td>
<td><%${u.state}%></td>
<td><%${u.country}%></td>
<td><%${u.pin_code}%></td>
<td><%${u.address_type}%></td>
</tr>
</c:forEach>