在jsp页面中,我无法访问从控制器类返回的Model对象

时间:2016-02-22 05:42:17

标签: spring jsp spring-mvc jstl

控制器类中的

一切正常(正如调试所说)。但是在返回jsp页面后我无法显示模型对象数据。在jsp页面中没有响应。

控制器

public class controller_fetch extends model.modelclass {

    SqlRowSet srs = null;
    ArrayList arraylist = null;

    public List<String> list() throws ClassNotFoundException {

        arraylist = new ArrayList();

        try {
            SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
            dataSource = new dbconnection.connection().getConnection(dataSource);
            JdbcTemplate jt = new JdbcTemplate(dataSource);
            String sql = "SELECT * FROM user_info";
            srs = jt.queryForRowSet(sql);
            while (srs.next()) {
                modelclass obj = new modelclass();
                obj.setEmailid(srs.getString("email_id"));
                obj.setPwd(srs.getString("pwd"));
                arraylist.add(obj);
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return arraylist;
    }

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public ModelAndView getdata(HttpServletRequest request, HttpServletResponse response) throws ClassNotFoundException {

        List<String> arraylists = list();

        //return back to index.jsp
        ModelAndView model = new ModelAndView("list");
        model.addObject("lists", arraylists);


        return model;

    }
}

JSP

<c:forEach items="${lists}" var="key">
<c:out value="${key.email_id}"></c:out>
<c:out value="${key.pwd}"></c:out>                
</c:forEach>

1 个答案:

答案 0 :(得分:0)

方法正在返回List, 但在列表中添加有对象 arraylist.add(OBJ); 什么是modelclass?

还尝试发送简单的字符串,看看它是否在JSP中打印。 避免在类名和变量名中使用下划线。