jsp之BBS的学习笔记Word文档下载推荐.docx
《jsp之BBS的学习笔记Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《jsp之BBS的学习笔记Word文档下载推荐.docx(32页珍藏版)》请在冰豆网上搜索。
怎么没有可能'
可能性是很大的'
大象进医院了'
insertintoarticlevalues(null,9,1,'
护士是蚂蚁'
在Myeclipse下创建一个web程序:
图一
修改webRoot下的index.jsp:
(红色代码是有效代码,其他的为美工设计)
<
%!
privatevoidtree(List<
Article>
articles,Connectionconn,intid,intgrade){
Stringsql="
select*fromarticlewherepid="
+id;
Statementstmt=DB.createStmt(conn);
ResultSetrs=DB.executeQuery(stmt,sql);
try{
while(rs.next()){
Articlea=newArticle();
a.initFromRs(rs);
a.setGrade(grade);
articles.add(a);
if(!
a.isLeaf()){
tree(articles,conn,a.getId(),grade+1);
}
}
}catch(SQLExceptione){
e.printStackTrace();
}finally{
DB.close(rs);
DB.close(stmt);
}
}%>
%
List<
articles=newArrayList<
();
Connectionconn=DB.getConn();
tree(articles,conn,0,0);
DB.close(conn);
%>
!
DOCTYPEHTMLPUBLIC"
-//W3C//DTDHTML4.0Transitional//EN"
>
html>
head>
title>
Java|Java世界_中文论坛|ChinaJavaWorld技术论坛:
Java语言*初级版<
/title>
metahttp-equiv="
content-type"
content="
text/html;
charset=GBK"
linkrel="
stylesheet"
type="
text/css"
href="
images/style.css"
title="
IntegratedStyles"
scriptlanguage="
JavaScript"
text/javascript"
src="
images/global.js"
/script>
alternate"
application/rss+xml"
RSS"
images/common.js"
/head>
body>
tableborder="
0"
cellpadding="
cellspacing="
width="
100%"
<
tbody>
tr>
tdwidth="
140"
ahref="
images/header-left.gif"
alt="
Java|Java世界_中文论坛|ChinaJavaWorld技术论坛"
border="
/a>
/td>
td>
imgsrc="
images/header-stretch.gif"
"
height="
57"
1%"
images/header-right.gif"
/tr>
/tbody>
/table>
br>
divid="
jive-forumpage"
trvalign="
top"
98%"
pclass="
jive-breadcrumbs"
论坛:
Java语言*初级版
(模仿)<
/p>
jive-description"
探讨Java语言基础知识,基本语法等大家一起交流共同提高!
谢绝任何形式的广告<
divclass="
jive-buttons"
tablesummary="
Buttons"
tdclass="
jive-icon"
post.jsp"
images/post-16x16.gif"
发表新主题"
16"
td>
aid="
jive-post-thread"
发表新主题<
/div>
3"
spanclass="
nobreak"
页:
1,316-<
jive-paginator"
[<
|<
class="
1<
jive-current"
2<
3<
4<
5<
6<
]<
/span>
99%"
jive-thread-list"
jive-table"
Listofthreads"
thead>
thclass="
jive-first"
colspan="
主题<
/th>
jive-author"
nobr>
作者
&
nbsp;
/nobr>
jive-view-count"
浏览
jive-msg-count"
nowrap="
nowrap"
回复<
jive-last"
最新帖子<
/thead>
for(Iterator<
it=articles.iterator();
it.hasNext();
){
Articlea=it.next();
StringpreStr="
;
for(inti=0;
i<
a.getGrade();
i++){
preStr+="
----"
%>
trclass="
jive-even"
jive-bullet"
images/read-16x16.gif"
已读"
--div-->
jive-thread-name"
95%"
jive-thread-1"
article_detail2.jsp?
id=<
%=a.getId()%>
%=preStr+a.getTitle()%>
104<
5<
jive-last-post"
%=newSimpleDateFormat("
yyyy-MM-ddHH:
mm:
ss"
).format(a.getPdate())%>
by:
jingjiangjun"
style="
jingjiangjun&
#187;
}
%--
jive-odd"
jive-thread-2"
兄弟们指点下那里错误,,,<
52<
2<
2007-9-13上午8:
40<
downing114"
downing114&
--%>
jive-legend"
/body>
/html>
显示的界面是一个树状结构的:
图二
Index.jsp
点击标题进入:
图三
%@pagecontentType="
language="
java"
import="
java.sql.*"
errorPage="
%@pageimport="
java.util.*"
%@pageimport="
com.lxy.BBS.DB"
com.lxy.BBS.Article"
%
StringstrId=request.getParameter("
id"
intid=0;
if(strId==null||strId.equals("
)){
out.println("
Error1"
+"
return;
}
try{
id=Integer.parseInt(strId);
}catch(NumberFormatExceptione){
Error2"
Articlea=newArticle();
Connectioncon=DB.getConn();
Stringstr="
select*fromarticlewhereid="
+id;
Statementst=DB.createStmt(con);
ResultSetrs=DB.executeQuery(st,str);
if(rs.next()){
a.initFromRs(rs);
DB.close(rs);
DB.close(st);
DB.close(con);
初学java遇一难题!
!
望大家能帮忙一下...<
jive-flatpage"
2Platform,StandardEdition(J2SE)<
jive-page-title"
主题:
%=a.getTitle()%>
jive-accountbox"
tablesummar