?? mybbs.jsp
字號:
<html>
<head>
<title>Java與XML結(jié)合起來制作的BBS系統(tǒng)</title>
</head>
<%@page contentType="text/html;charset=GB2312"%>
<%@page import="java.io.*,org.xml.sax.*,javax.xml.parsers.*,org.w3c.dom.*"%>
<jsp:useBean id="bbs" class="test.MyBBSBean" />
<body bgcolor="#CFF1E1">
<center><h2>
My Little BBS
</h2></center>
<a href="postform.jsp">發(fā)表高見</a><br>
<%
Document doc=null;
File xmlFile = new File(request.getRealPath("/") + "bbs.xml");
//下面是獲取客戶端請求信息的部分
String strUserName = request.getParameter("username"); //尊姓大名
String strTitle = request.getParameter("title"); //文章標題
String strContent = request.getParameter("content"); //文章內(nèi)容
String strPost = request.getParameter("post"); //發(fā)表(包括新發(fā)表和回復(fù))
String strReply = request.getParameter("reply"); //回復(fù)
//檢查XML文檔是否存在
if(doc==null)
{
//如果文檔不存在,則使用解析器解析生成
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setIgnoringComments(true);
dbf.setIgnoringElementContentWhitespace(true);
DocumentBuilder db = dbf.newDocumentBuilder();
try{
doc=db.parse("file:///" + request.getRealPath("/") + "bbs.xml");
}catch(Exception e ){
out.println(e.toString());
}
}
bbs.setDocument(doc);
if(strPost!=null)
{
//如果發(fā)表文章
if( strUserName == null || strUserName.length()==0 )
out.println("<font color='red'><h3>用戶名不能為空!<a href=\"javascript:history.back();\">重試</a></h3></font>");
else if( strTitle == null || strTitle.length()==0 )
out.println("<font color='red'><h3>標題不能為空!<a href=\"javascript:history.back();\">重試</a></h3></font>");
else if( strContent == null || strContent.length()==0 )
out.println("<font color='red'><h3>文章內(nèi)容不能為空!<a href=\"javascript:history.back();\">重試</a></h3></font>");
else{
strUserName=new String(strUserName.getBytes("iso8859-1"), "gb2312");
strTitle=new String(strTitle.getBytes("iso8859-1"), "gb2312");
strContent=new String(strContent.getBytes("iso8859-1"), "gb2312");
bbs.insertElement( strReply, strUserName, strTitle, strContent);
bbs.put(out,doc.getDocumentElement() );
}
}else{
//如果沒有發(fā)表文章
bbs.put(out,doc.getDocumentElement());
}
%>
</body>
</html>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -