?? list_notes.jsp
字號:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.util.*"%>
<%@ page import="cn.mldn.lxh.note.vo.*"%>
<html>
<head>
<title>MVC+DAO 留言管理程序——登陸</title>
</head>
<body>
<center>
<h1>留言管理范例 —— MVC + DAO實現</h1>
<hr>
<br>
<%
// 編碼轉換
request.setCharacterEncoding("GB2312") ;
if(session.getAttribute("uname")!=null)
{
// 用戶已登陸
%>
<%
// 如果有內容,則修改變量i,如果沒有,則根據i的值進行無內容提示
int i = 0 ;
String keyword = request.getParameter("keyword") ;
List all = null ;
all = (List)request.getAttribute("all") ;
%>
<form action="Note" method="POST">
請輸入查詢內容:<input type="text" name="keyword">
<input type="hidden" name="status" value="selectbylike">
<input type="submit" value="查詢">
</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?id=<%=id%>&status=selectid"><%=title%></a></td>
<td><%=author%></td>
<td><%=content%></td>
<td><a href="Note?id=<%=id%>&status=delete">刪除</a></td>
</tr>
<%
}
// 判斷i的值是否改變,如果改變,則表示有內容,反之,無內容
if(i==0)
{
// 進行提示
%>
<tr>
<td colspan="5">沒有任何內容?。?!</td>
</tr>
<%
}
%>
</table>
<%
}
else
{
// 用戶未登陸,提示用戶登陸,并跳轉
response.setHeader("refresh","2;URL=login.jsp") ;
%>
您還未登陸,請先登陸!??!<br>
兩秒后自動跳轉到登陸窗口!!!<br>
如果沒有跳轉,請按<a href="login.jsp">這里</a>?。。?lt;br>
<%
}
%>
</center>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -