在JSP中呈现列表
尝试在JSP中输出数组时遇到问题:在JSP中呈现列表,jsp,spring-mvc,jstl,Jsp,Spring Mvc,Jstl,尝试在JSP中输出数组时遇到问题: @RequestMapping(value="/searchResult.do", method = RequestMethod.POST) ModelAndView search(HttpServletRequest request, HttpServletResponse response) throws SQLException { String keyword = request.getParameter("keyword"); St
@RequestMapping(value="/searchResult.do", method = RequestMethod.POST)
ModelAndView search(HttpServletRequest request, HttpServletResponse response) throws SQLException
{
String keyword = request.getParameter("keyword");
String within = request.getParameter("witin");
String status = request.getParameter("status");
String query="select id,title,description,story_type,uploaded_date,popularity from story where status='"+status+"' and title like '"+'%'+keyword+'%'+"'";
stmt= (Statement) DBManager.getMyConnection();
rs = stmt.executeQuery(query);
Map map = new HashMap();
List wordList = new ArrayList();
if(keyword!=null){
while (rs.next()) {
String id = rs.getString("id");
String title = rs.getString("title");
String description = rs.getString("description");
String parent = rs.getString("uploaded_date");
String type = rs.getString("story_type");
String pop = rs.getString("popularity");
wordList.add(id);
wordList.add(title);
wordList.add(type);
wordList.add(description);
wordList.add(parent);
wordList.add(pop);
map.put("wordList", wordList);
}
return new ModelAndView("searchResult",map);
}
return new ModelAndView("search");
}
在JSP中,我使用打印的${wordList}
[20,印度赢得了世界杯,体育,这
是我的杯子,2011-03-26,2,27,印度
赢得世界杯,体育,xyz,2011-04-08,
2]
…这是一个数组中的两条记录
如何在JSP中打印单独一行中的每个项目?名为wordList的变量是一个集合。要显示集合的元素,可以使用forEach 这方面有一个很好的例子,还有一个较短的例子