jsp获取struts2查询到的数据
1.在struts2的方法中利用查询语句查询到结果,然后再对结果进行封装,jsp根据封装获取相关信息
struts2的查询和封装方法:
private List<FreeMarkerDetail> freemarkerdetaillist;
这个是封装的方法类
/** * @Title: queryFeedBackById * @Description: 根据意见反馈Id查询意见反馈详情 * @param @return * @param @throws ServiceException 参数 * @return String 返回类型 * @throws */
public String queryFreeMarkerById() throws ServiceException{ freemarkerdetaillist = freemarkerDetailService.queryFreeMarkerDetailById(freemarkerId); ServletActionContext.getRequest().setAttribute("freemarkerdetailList", freemarkerdetaillist); return "toFreeMarkerDetailPage"; }
2.然后安装 ServletActionContext.getRequest().setAttribute("freemarkerdetailList", freemarkerdetaillist); 进行封装
3.jsp页面根据封装获取相关内容:
<table class="sx_table"> <tr> <td style="width: 10%"><label class="name">主键编号</label></td> <td style="width: 10%"><label class="name">关联主键</label></td> <td style="width: 10%"><label class="name">文件名</label></td> <td style="width: 50%"><label class="name">文件路径</label></td> <td style="width: 20%"><label class="name">创建时间</label></td> </tr> <c:forEach items="${requestScope.freemarkerdetailList }" var="freemarkerdetailList"> <tr> <td style="width: 10%"><label class="name"></label> <span class="toname"> ${freemarkerdetailList.filesDetailId} </span></td> <td style="width: 10%"><label class="name"></label> <span class="toname"> ${freemarkerdetailList.filesId} </span></td> <td style="width: 10%"><label class="name"></label> <span class="toname"> ${freemarkerdetailList.filesDetailName } </span></td> <td style="word-break:break-all; word-wrap:break-word; width: 50%;"><label class="name"></label> <span class="toname"> <a href="${freemarkerdetailList.filesDetailUrl }"> ${freemarkerdetailList.filesDetailUrl }</a> </span> </td> <td style="width: 20%"><label class="name"></label> <span class="toname"> <fmt:formatDate value="${freemarkerdetailList.createTime }" pattern="yyyy-MM-dd HH:mm:ss" /> </span></td> </tr> </c:forEach> </table>
上面就是jsp获取查询到内容的方法。
不定期会发布一些实用的Java开发文章