Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从控制器传递到jsp时获取空对象_Jsp_Spring Mvc_Hibernate 4.x - Fatal编程技术网

从控制器传递到jsp时获取空对象

从控制器传递到jsp时获取空对象,jsp,spring-mvc,hibernate-4.x,Jsp,Spring Mvc,Hibernate 4.x,我在将对象列表从控制器传递到jsp时遇到问题。 这里是jsp页面 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Tran

我在将对象列表从控制器传递到jsp时遇到问题。 这里是jsp页面

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
 <!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>Users</title>
</head>
 <body>
 <h1>User list</h1>

   <c:url var="editImgUrl" value="/edit.png" />
   <c:url var="deleteImgUrl" value="/delete.png" />

<table style="border: 1px solid; width: 100%; text-align:center">
    <thead style="background:#d3dce3">
        <tr>
            <th>Id</th>
            <th>First Name</th>
            <th>Last Name</th>
            <th>login</th>
            <th>service line</th>
            <th colspan="2"></th>
        </tr>
    </thead>
    <tbody style="background:#ccc">
    <c:forEach items="${userList}" var="user">
        <c:url var="editUrl" value="/edit?id=${user.iduser}" />
        <c:url var="deleteUrl" value="/delete?id=${user.iduser}" />

        <tr>
            <td>${user.iduser}</td>
            <td><c:out value="${user.firstName}" /></td>
            <td><c:out value="${user.lastName}" /></td>
            <td><c:out value="${user.login}" /></td>
            <td><c:out value="${user.serviceline}" /></td>

 <td><a href="edit?id=${user.id_user}"><img src="${editImgUrl}"></img></a></td>  
  <td><a href="delete?id=${user.id_user}"><img src="${deleteImgUrl}"></img></a>        </td>  

   </tr>

  </c:forEach>
   </tbody>
  </table>

   <a href="list3">Click Here to see user List</a>  
 </body>
</html>

使用者
用户列表
身份证件
名字
姓
登录
服务线
${user.iduser}
这是我的控制器:

    package test3.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import test3.model.entities.User;
import test3.service.UserService;

@Controller
public class UserController {

    @Autowired  
     public UserService userService; 

     @RequestMapping("form")  
     public String viewRegistration(Map<String, Object> model) {
            User user = new User();    
            model.put("user", user);

          /**  List<String> servicelineList = new ArrayList<String>();
            servicelineList.add("ADM");
            servicelineList.add("PBS");
            servicelineList.add("CSD");
            model.put("servicelineList", servicelineList);**/

            return "form";
     }  

     @RequestMapping("register")  
     public ModelAndView registerUser(@ModelAttribute User user) {  
      userService.add(user);
      return new ModelAndView("redirect:list");  
     }  



     @RequestMapping(value="list", method = RequestMethod.GET)  
     public ModelAndView getAll(){ 
         ModelAndView model=new  ModelAndView("list");
     try {
        model.addObject("userList",userService.getAll());
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }  
      return model;
     }  

     public String getUser(Map<String, Object> model) {
            User user = new User();    
            model.put("user", user);

          /**  List<String> servicelineList = new ArrayList<String>();
            servicelineList.add("ADM");
            servicelineList.add("PBS");
            servicelineList.add("CSD");
            model.put("servicelineList", servicelineList);**/

            return "form";
     }  

}
包test3.controller;
导入java.util.ArrayList;
导入java.util.List;
导入java.util.Map;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.stereotype.Controller;
导入org.springframework.ui.Model;
导入org.springframework.web.bind.annotation.ModelAttribute;
导入org.springframework.web.bind.annotation.RequestMapping;
导入org.springframework.web.bind.annotation.RequestMethod;
导入org.springframework.web.servlet.ModelAndView;
导入test3.model.entities.User;
导入test3.service.UserService;
@控制器
公共类用户控制器{
@自动连线
公共用户服务用户服务;
@请求映射(“表单”)
公共字符串视图注册(地图模型){
用户=新用户();
model.put(“用户”,user);
/**List servicelineList=newarraylist();
servicelineList.add(“ADM”);
servicelineList.添加(“PBS”);
servicelineList.add(“CSD”);
model.put(“servicelineList”,servicelineList)**/
返回“表格”;
}  
@请求映射(“寄存器”)
公共模型和视图注册器(@modeldattribute User){
添加(用户);
返回新的ModelAndView(“重定向:列表”);
}  
@RequestMapping(value=“list”,method=RequestMethod.GET)
公共模型和视图getAll(){
ModelAndView模型=新的ModelAndView(“列表”);
试一试{
addObject(“userList”,userService.getAll());
}捕获(例外e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}  
收益模型;
}  
公共字符串getUser(映射模型){
用户=新用户();
model.put(“用户”,user);
/**List servicelineList=newarraylist();
servicelineList.add(“ADM”);
servicelineList.添加(“PBS”);
servicelineList.add(“CSD”);
model.put(“servicelineList”,servicelineList)**/
返回“表格”;
}  
}
这是我得到的观点:

包含以下值的表:$user.iduser、$user.lastname。。。(我不能上传照片)

我以为查询的结果是空的,但我试图传递一个字符串列表,却遇到了同样的问题


谢谢你的帮助

我通过添加

<%@ page isELIgnored="false" %>


你能澄清一下你到底在调用哪个方法来重新设计你列出的视图层吗?我解决了这个问题。我把答案放在下面。谢谢你的回答