?? list_notes.jsp
字號:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
<%@ page import="org.lxh.struts.note.vo.*"%>
<%@ page import="java.util.*"%>
<html>
<head>
<title>Struts+DAO 留言管理程序——登陸</title>
</head>
<body>
<center>
<h1>
留言管理范例 —— Struts + DAO實現
</h1>
<hr>
<br>
<logic:present name="uname" scope="session">
<%
// 如果有內容,則修改變量i,如果沒有,則根據i的值進行無內容提示
int i = 0;
String keyword = request.getParameter("keyword");
List all = null;
all = (List) request.getAttribute("all");
%>
<html:form action="note.do" method="POST">
請輸入查詢內容:
<input type="text" name="keyword">
<input type="hidden" name="status" value="selectlike">
<input type="submit" value="查詢">
</html:form>
<h3>
<a href="insert.jsp">添加新留言</a>
</h3>
<table width="80%" border="1">
<tr>
<td>
留言ID
</td>
<td>
標題
</td>
<td>
作者
</td>
<td>
內容
</td>
<td>
刪除
</td>
</tr>
<%
Iterator iter = all.iterator();
while (iter.hasNext()) {
Note note = (Note) iter.next();
i++;
// 進行循環打印,打印出所有的內容,以表格形式
// 從數據庫中取出內容
int id = note.getId();
String title = note.getTitle();
String author = note.getAuthor();
String content = note.getContent();
// 因為要關鍵字返紅,所以此處需要接收查詢關鍵字
// String keyword = request.getParameter("keyword") ;
if (keyword != null) {
// 需要將數據返紅
title = title.replaceAll(keyword, "<font color=\"red\">"
+ keyword + "</font>");
author = author.replaceAll(keyword, "<font color=\"red\">"
+ keyword + "</font>");
content = content.replaceAll(keyword,
"<font color=\"red\">" + keyword + "</font>");
}
%>
<tr>
<td>
<%=id%>
</td>
<td>
<a href="note.do?id=<%=id%>&status=selectid"><%=title%> </a>
</td>
<td>
<%=author%>
</td>
<td>
<%=content%>
</td>
<td>
<a href="note.do?id=<%=id%>&status=delete">刪除</a>
</td>
</tr>
<%
}
// 判斷i的值是否改變,如果改變,則表示有內容,反之,無內容
if (i == 0) {
// 進行提示
%>
<tr>
<td colspan="5">
沒有任何內容!!!
</td>
</tr>
<%
}
%>
</table>
</logic:present>
<logic:notPresent name="uname" scope="session">
<%
// 用戶未登陸,提示用戶登陸,并跳轉
response.setHeader("refresh", "2;URL=login.jsp");
%>
您還未登陸,請先登陸!!!<br>
兩秒后自動跳轉到登陸窗口!!!<br>
如果沒有跳轉,請按<a href="login.jsp">這里</a>!!!<br>
</logic:notPresent>
</center>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -