// 前台jsp应用
<script type="text/javascript">
function sel(currentPage)
{
document.forms['logsListForm'].curr.value=currentPage;
document.forms['logsListForm'].submit();
}
</script>
<form action="iotlogs.do" method="post" name="logsListForm">
<input type="hidden" name="method" value="${judge}"/>
<table border="1" cellspacing="0" cellpadding="0" width="950" align="center">
<tr><td align="center" colspan="6" style="height: 30px;">日志信息</td></tr>
<tr align="center">
<td>日志ID</td>
<td>用户id</td>
<td>用户名</td>
<td>日志时间</td>
<td>日志内容</td>
<td>用户请求URL</td>
</tr>
<logic:notEmpty name="logsList">
<logic:iterate id="logs" name="logsList">
<tr align="center">
<td>${logs.logid}</td>
<td>${logs.uid}</td>
<td>${logs.username}</td>
<td>${logs.requestTime}</td>
<td>${logs.description}</td>
<td>${logs.requestPath}</td>
</tr>
</logic:iterate>
</logic:notEmpty>
<logic:empty name="logsList">
<tr><td colspan="6" align="center">没有你要的信息</td></tr>
</logic:empty>
<tr><td colspan="6" align="center">
<table cellspacing="1" cellpadding="1" width="99%" align="center"
bgcolor="#d5e8f6" border="0">
<tr bgcolor="#d5e8f6">
<td height="50" align="right">
<input type="hidden" name="curr" value="${requestScope.current}" />
总记录${requestScope.allCount}, 当前第${requestScope.current} 页/共
${requestScope.pageSize}页
<input type="button" value="首页" onclick="sel(1)"
${requestScope.current==1? "disabled":""}/>
<input type="button" value="上一页"
onclick="sel(${requestScope.current-1})"
${requestScope.current==1? "disabled":""}/>
<input type="button" value="下一页"
onclick="sel(${requestScope.current+1})"
${requestScope.current==requestScope.pageSize? "disabled":""}/>
<input type="button" value="末页"
onclick="sel(${requestScope.pageSize})"
${requestScope.current==requestScope.pageSize? "disabled":""}/>
</td>
</tr>
</table>
</td></tr>
</table>
</form>
// 后台方法及调用
// BOInterface
public List<IotLogsForm> findAllByPage(Integer currPage,Integer pageNum);
// BOImplements
public List<IotLogsForm> findAllByPage(Integer currPage, Integer pageNum) {
List<IotLogsForm> listLogsForm = new ArrayList<IotLogsForm>();
try {
List<IotLogs> listLogs = iotLogsDAO.findAllByPage(currPage, pageNum);
for(IotLogs logs : listLogs){
IotLogsForm logsF = new IotLogsForm();
BeanUtils.copyProperties(logsF, logs);
listLogsForm.add(logsF);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return listLogsForm;
}
// DAOInterface
public List<IotLogs> findAllByPage(Integer currPage,Integer pageNum);
// DAOImplements
public List<IotLogs> findAllByPage(Integer currPage, Integer pageNum) {
Session session = this.getSession();
List<IotLogs> listlogs = new ArrayList<IotLogs>();
String sql = "from IotLogs order by logid desc ";
Query query = session.createQuery(sql);
int first = (currPage - 1) * pageNum;
query.setFirstResult(first);
query.setMaxResults(pageNum);
listlogs = query.list();
session.close();
return listlogs;
}
// Action调用
public ActionForward showAll(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
HttpSession session =request.getSession();
if (session.getAttribute("Loginname") == null) {
return new ActionForward("/login.jsp");
}
int pageNum = 10;
int currPage = 1;
int allCount = 0;
String cps = request.getParameter("curr");
if (cps != null && cps.length() > 0) {
currPage = Integer.parseInt(cps);
}
List<IotLogsForm> logsAllCount = iotLogsManager.showAll();
if(!logsAllCount.isEmpty()){
allCount = logsAllCount.size();
}
int pageCount = (allCount + pageNum - 1) / pageNum;
if (currPage < 1) {
currPage = 1;
}
if (currPage > pageCount) {
currPage = pageCount;
}
List<IotLogsForm> listLogsForm = iotLogsManager.findAllByPage(currPage, pageNum);
request.setAttribute("logsList", listLogsForm);
request.setAttribute("current", currPage);// 当前页
request.setAttribute("allCount", allCount);// 总记录数
request.setAttribute("pageSize", pageCount);// 页大小
request.setAttribute("judge", "showAll");
return new ActionForward("/manager/iotLogsList.jsp");
}