标题:JSP+ACCESS做的一个简易论坛
只看楼主
当当
Rank: 1
等 级:新手上路
帖 子:235
专家分:0
注 册:2004-4-30
 问题点数:0 回复次数:19 
JSP+ACCESS做的一个简易论坛

在JB9+win98下编译成功并能运行,如果大家用JB2005的话,请自己新建一个工程,再建一个web应用程序,再将附件中的JSP文件复印到自己创建的工程下即可运行,数据库用DSN配置一个BBSDSN的数据源,就应该能够运行了.
源码如下,
一. userlogin(登录页面)
<%@ page contentType="text/html; charset=GB2312" %>
<html>
<head>
<script language=JavaScript>
function checkform(formlogin)
{
var flag = true;
if(formlogin.userName.value == "" || formlogin.userName.value == null)
{
alert("用户名不能为空!");
formlogin.userName.focus();
flag = false;
}
else if(formlogin.userPassword.value == "" || formlogin.userPassword.value == null)
{
alert("密码栏不能为空!");
formlogin.userPassword.focus();
flag = false;
}
return flag;
}
</script>
<title>欢迎光临阿当论坛--用户登录</title>
</head>
<body bgcolor=#7ADA93>
<BR><BR><BR><BR>
<p align="center"><b><font size="7" face="华文彩云" color=#006699><span style="letter-spacing: 50">阿当论坛</span></font></b></p>
<p align="center"><b><span style="letter-spacing: 26"><font color=#006699 face="华文彩云" size="4">WELCOME</font></span></b></p>
<p align="center"><span style="letter-spacing: 26"><font face="华文彩云" size="5" color=#006699><b>用户登录</b></font></span></p>

<form method="POST" action="checklogin.jsp" name="formlogin" onsubmit="return checkform(this)">
<p align="center"><font size="3" face="华文中宋" color=#006699>用户名 </font><input type="text" name="userName" size="20"><br>
<font face="华文中宋" size="3" color=#006699>密 &nbsp;&nbsp;码 </font><input type="Password" name="userPassword" size="20"></p>
<p align="center"><input type="submit" value="登录">&nbsp;&nbsp;&nbsp;
<a href=createNewUser.jsp><font size=1 face=宋体>注册新用户</font></a></p>
</form>

<HR size=5>
<TABLE align=center width=37% >
<TR >
<TD><FONT SIZE=1pt COLOR=#006699 face=宋体>由于初学JSP,所以界面简陋,功能简单,敬请原谅!<br>由于经验有限,此论坛只有注册用户才能进入.<br>我的座右铭:努力努力再努力,我一定会成功!</FONT></TD>
</TR>
</TABLE>
</body>
</html>

b0L3JSUC.rar (218.65 KB) JSP+ACCESS做的一个简易论坛


[此贴子已经被作者于2006-7-15 10:45:03编辑过]

搜索更多相关主题的帖子: JSP ACCESS 论坛 
2006-07-15 10:30
当当
Rank: 1
等 级:新手上路
帖 子:235
专家分:0
注 册:2004-4-30
得分:0 

二.checklogin(检测用户名是否合法)
<%@ page contentType="text/html; charset=GB2312" %>
<%@ page import = "java.sql.*" %>
<%
response.setContentType("text/html; charset=GB2312");
request.setCharacterEncoding("GB2312");

//获取userlogin页面的用户名和密码值
String userName = request.getParameter("userName");
String userPassword = request.getParameter("userPassword");
//连接数据库,进行查询看是否有此用户
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn = DriverManager.getConnection("jdbc:odbc:BBSDSN");
Statement st = cn.createStatement();
String sql = "select * from BBS_USER where USERNAME='" + userName + "' and Password='" + userPassword + "'";
ResultSet rs = st.executeQuery(sql);

if(rs.next())
{
session.setAttribute("userName", userName);//将用户名放入session
response.sendRedirect("bbsmain.jsp"); //转到论坛页面
}
else
{
out.print("<html><head><title>欢迎光临阿当论坛--登录错误</title><head><body bgcolor=#7ADA93><br><br><center>");
out.print("<font face=宋体 size=1>对不起,用户名或密码错误!请重新输入!<br><br>");
out.print("<a href=userlogin.jsp>返回</a></font>");
out.print("</center></body></html>");
}

rs.close();
st.close();
cn.close();
}
catch(Exception e)
{
e.printStackTrace();
}
%>


学好编程就能编出自己的未来! 加油!自信!努力!奋斗!
2006-07-15 10:31
当当
Rank: 1
等 级:新手上路
帖 子:235
专家分:0
注 册:2004-4-30
得分:0 

三.createNewUser(新用户注册页面)
<%@ page contentType="text/html; charset=GB2312" %>
<html>
<script language=JavaScript>
function checkform(formlogin)
{
var flag = true;
if(formNewUser.userName.value == "" || formNewUser.userName.value == null)
{
alert("请输入用户名!");
formNewUser.userName.focus();
flag = false;
}
else if(formNewUser.userPassword1.value == "" || formNewUser.userPassword1.value == null)
{
alert("请输入用户密码!");
formNewUser.userPassword1.focus();
flag = false;
}
else if(formNewUser.userPassword2.value == "" || formNewUser.userPassword2.value == null)
{
alert("请确认用户密码!");
formNewUser.userPassword2.focus();
flag = false;
}
else if(formNewUser.userEmail.value == "" || formNewUser.userEmail.value == null)
{
alert("请输入用户邮箱!");
formNewUser.userEmail.focus();
flag = false;
}
return flag;
}
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>欢迎光临阿当论坛--用户注册</title>
</head>
<body bgcolor=#7ADA93>
<p align="center"><span style="letter-spacing: 5"><font face="宋体" size="1"><b>新用户注册</b></font></span></p>
<p align="center"><font face="宋体" size="1">请认真填写以下信息</font></p>
<CENTER>
<FORM METHOD=POST ACTION="checkNewUser.jsp" name="formNewUser" onsubmit="return checkform(this)">
<TABLE width=60%>
<TR>
<TD width=15%><font face="宋体" size="1">用户名</font></TD>
<TD width=45%><INPUT TYPE="text" NAME="userName"></TD>
<TD width=40%><FONT SIZE="1" face="宋体">☆请不要超出20个字符的长度</FONT></TD>
</TR>
<TR>
<TD width=15%><FONT SIZE="1" face="宋体">用户密码</FONT></TD>
<TD width=45%><INPUT TYPE="Password" NAME="userPassword1"></TD>
<TD width=40%><FONT SIZE="1" face="宋体">☆请不要超出12个字符的长度</FONT></TD>
</TR>
<TR>
<TD width=15%><FONT SIZE="1" face="宋体">确认密码</FONT></TD>
<TD width=45%><INPUT TYPE="Password" NAME="userPassword2"></TD>
<TD width=40%><FONT SIZE="1" face="宋体">☆请与上面的密码保存一致</FONT></TD>
</TR>
<TR>
<TD width=15%><FONT SIZE="1" face="宋体">用户邮箱</FONT></TD>
<TD width=45%><INPUT TYPE="text" NAME="userEmail" size=40></TD>
<TD width=40%><FONT SIZE="1" face="宋体">☆请输入正确的邮箱地址</FONT></TD>
</TR>
</TABLE>
<BR><BR>
<INPUT TYPE="submit" value="确定">&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="reset" value="重新填写">
</FORM>
<br><hr><BR>
<FONT SIZE="1" face="宋体"><a href="userlogin.jsp">返回登录页面</a></FONT>
</CENTER>
</body>
</html>


学好编程就能编出自己的未来! 加油!自信!努力!奋斗!
2006-07-15 10:32
当当
Rank: 1
等 级:新手上路
帖 子:235
专家分:0
注 册:2004-4-30
得分:0 

四.checkNewUser(检测新用户是否合法)
<%@ page contentType="text/html; charset=GB2312" %>
<%@ page import = "java.sql.*" %>
<%@ page import = "java.util.*" %>

<%
response.setContentType("text/html; charset=GB2312");
request.setCharacterEncoding("GB2312");

String userName = request.getParameter("userName");
String userPassword1 = request.getParameter("userPassword1");
String userPassword2 = request.getParameter("userPassword2");
String userEmail = request.getParameter("userEmail");

if(!userPassword1.equals(userPassword2))
{
String HTML = "<html><head><title>用户注册--错误信息</title></head><body bgcolor=#7ADA93><center>";
HTML += "<font face=宋体 size=1>两次密码输入不一致,请<a href='createNewUser.jsp'>";
HTML += "<b>返回</b></a>重新填写!</font></center></body></html>";
out.print(HTML);
}
else
{
if( (userEmail.length() <= 7) ||
(userEmail.charAt(0) == '@') ||
(userEmail.charAt(userEmail.length()-1) == '@') )
{
String HTML = "<html><head><title>用户注册--错误信息</title></head><body bgcolor=#7ADA93>";
HTML += "<center><font face=宋体 size=1>请输入正确邮箱地址,请<a href='createNewUser.jsp'>";
HTML += "<b>返回</b></a>重新填写!</font></center></body></html>";
out.print(HTML);
}
else
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn = DriverManager.getConnection("jdbc:odbc:BBSDSN");
Statement st = cn.createStatement();
String sql = "select * from BBS_USER where USERNAME='" + userName + "'";
ResultSet rs = st.executeQuery(sql);

if(rs.next())
{
String HTML = "<html><head><title>用户注册--错误信息</title></head>";
HTML += "<body bgcolor=#7ADA93><center><font face=宋体 size=1>用户名已被占用,";
HTML += "请<a href='createNewUser.jsp'>";
HTML += "<b>返回</b></a>重新填写!</font></center></body></html>";
out.print(HTML);
}
else
{
sql = "insert into BBS_USER(USERNAME,PASSWORD,EMAIL) VALUES('";
sql += userName + "','" + userPassword1 + "','" + userEmail+ "')";
st.executeUpdate(sql);

session.setAttribute("userName", userName);

String HTML = "<html><head><title>用户注册--注册成功</title></head>";
HTML += "<body bgcolor=#7ADA93><center><font face=宋体 size=1>恭喜您,注册用户成功!";
HTML += "</font></center><br><br>";
HTML += "<center><font face=宋体 size=1>请<a href=bbsmain.jsp>点击这里</a>跳转至论坛……";
HTML += "</font></center></body></html>";
out.print(HTML);
}
rs.close();
st.close();
cn.close();
}
catch(SQLException e)
{
e.getMessage();
}
}
}
%>


学好编程就能编出自己的未来! 加油!自信!努力!奋斗!
2006-07-15 10:33
当当
Rank: 1
等 级:新手上路
帖 子:235
专家分:0
注 册:2004-4-30
得分:0 

四.BBSMAIN(论坛帖子列表,主页面)
<%@ page contentType="text/html; charset=GB2312" %>
<%@ page import = "java.sql.*" %>

<%
response.setContentType("text/html; charset=GB2312");
request.setCharacterEncoding("GB2312");

String userName_s = (String)session.getAttribute("userName"); //获取用户名
%>
<html>
<head><title>欢迎光临阿当论坛-论坛主页</title></head>
<body bgcolor=#CCFFFF>
<table border="0" width="100%">
<tr>
<td width="100%"><font face="宋体" size="1">欢迎<b><font color="#FF0000"><%=userName_s%></font></b>光临阿当论坛</font><br></td>
</tr>
<tr>
<td width="100%">
<p align="right"><font face="宋体" size="1"><A HREF="NewTitle.jsp">发表新话题</A></font></td>
</tr>
</table>
<br>
<center><h6><font color=green>欢迎光临阿当论坛在线讨论区--JSP专区</font></h6></center>
<center><table border=1 width=80% bordercolor=#000000 bordercolordark=#FFFFFF>
<tr><td width=20% align=center><font face=宋体 size=1>日期</font></td>
<td width=60% align=center><font face=宋体 size=1>主题</font></td>
<td width=20% align=center><font face=宋体 size=1>作者</font></td></tr>

<%
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn = DriverManager.getConnection("jdbc:odbc:BBSDSN");
Statement st = cn.createStatement();
String sql = "SELECT * FROM BBS_TEXT WHERE ROOTID=0 ORDER BY ID DESC";
ResultSet rs = st.executeQuery(sql);
while(rs.next())
{
String lasttime = rs.getString("LASTTIME");
String title = rs.getString("TITLE");
String userName = rs.getString("USERNAME");
int ID = rs.getInt("ID");

out.print("<tr>");
out.print("<td width=20% align=center><font face=宋体 size=1>" + lasttime + "</font></td>");
out.print("<td width=60% align=center><font face=宋体 size=1><a href=backCallTitle.jsp?id=" + ID + ">" + title + "</a></font></td>");
out.print("<td width=20% align=center><font face=宋体 size=1>" + userName + "</font></td>");
out.print("</tr>");
}
out.print("</table></center>");

rs.close();
st.close();
cn.close();
}
catch(Exception e)
{
e.printStackTrace();
}
%>
</body>
</html>



学好编程就能编出自己的未来! 加油!自信!努力!奋斗!
2006-07-15 10:34
当当
Rank: 1
等 级:新手上路
帖 子:235
专家分:0
注 册:2004-4-30
得分:0 

五.NewTitle(发表新话题)
<%@ page contentType="text/html; charset=GB2312" %>
<HTML>
<HEAD>
<script language=JavaScript>
function checkform(formNewTitle)
{
var flag = true;
if(formNewTitle.txttitle.value == "" )
{
alert("主题不能为空!");
formNewTitle.txttitle.focus();
flag = false;
}
else if(formNewTitle.txtmain.value == "" )
{
alert("正文不能为空!");
formNewTitle.txtmain.focus();
flag = false;
}
return flag;
}
</script>
<TITLE>欢迎光临阿当论坛--发表新贴</TITLE>
</HEAD>
<BODY bgcolor=#CCFFFF>
<CENTER><FONT SIZE="1" COLOR="green"><B>阿当论坛--新贴发表</B></FONT></CENTER>
<BR>
<CENTER>

<FORM METHOD=POST ACTION="saveTitle.jsp" NAME="formNewTitle" onsubmit="return checkform(this)">
<TABLE border=1 width=68% bordercolor=#000000 bordercolordark=#FFFFFF>
<TR>
<TD><FONT SIZE="1" face=宋体><B>主题</B></FONT>:&nbsp;<INPUT TYPE="text" NAME="txttitle" size=83></TD>
</TR>
<TR>
<TD><FONT SIZE="1" face=宋体><B>正文</B></FONT>:<BR><TEXTAREA NAME="txtmain" ROWS="25" COLS="90"></TEXTAREA></TD>
</TR>
</TABLE>
<BR>
<INPUT TYPE="submit" value="发表">&nbsp;&nbsp;&nbsp;&nbsp;<INPUT TYPE="reset" value="重写">
</FORM>

</CENTER>
</BODY>
</HTML>


学好编程就能编出自己的未来! 加油!自信!努力!奋斗!
2006-07-15 10:35
当当
Rank: 1
等 级:新手上路
帖 子:235
专家分:0
注 册:2004-4-30
得分:0 

六.saveTitle(保存话题)

<%@ page contentType="text/html; charset=GB2312" %>
<%@ page import = "java.sql.*" %>
<%@page import="java.util.*"%>
<%
response.setContentType("text/html; charset=GB2312");
request.setCharacterEncoding("GB2312");

String userName = (String)session.getAttribute("userName"); //获取用户名
String title = request.getParameter("txttitle");//获取标题
String txtmain = request.getParameter("txtmain");//获取正文内容
String userEmail = null;
//获取时间
int year, month, day, hour, minute, second;
String time;
GregorianCalendar calendar = new GregorianCalendar();
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH) + 1;
day = calendar.get(Calendar.DAY_OF_MONTH);
hour = calendar.get(Calendar.HOUR_OF_DAY);
minute = calendar.get(Calendar.MINUTE);
second = calendar.get(Calendar.SECOND);
time = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;

//连接数据库
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn = DriverManager.getConnection("jdbc:odbc:BBSDSN");
Statement st = cn.createStatement();
String sql = "select EMAIL from BBS_USER where USERNAME='" + userName + "'";
ResultSet rs = st.executeQuery(sql);
if(rs.next())
{
userEmail = rs.getString("EMAIL");//获取用户注册时写的EAMIL
}

//将发贴内容写入数据库
sql = "insert into BBS_TEXT(ROOTID,TITLE,USERNAME,EMAIL,TEXTMAIN,LASTTIME) VALUES(0,'";
sql += title + "','" + userName + "','" + userEmail + "','" + txtmain + "','" + time + "')";
st.executeUpdate(sql);

String HTML = "<html><head><title>阿当论坛--发贴成功</title></head><body bgcolor=#CCFFFF>";
HTML += "<br><br><center><font face='宋体' size=1>恭喜您,您的贴子已经成功存入数据库!</font>";
HTML += "<br><br><a href='bbsmain.jsp'><font face='宋体' size=1>返回论坛主页</font></a></center></body></html>";
out.println(HTML);

rs.close();
st.close();
cn.close();
}
catch(Exception e)
{
e.printStackTrace();
}
%>


学好编程就能编出自己的未来! 加油!自信!努力!奋斗!
2006-07-15 10:35
当当
Rank: 1
等 级:新手上路
帖 子:235
专家分:0
注 册:2004-4-30
得分:0 

七.backcall(回复页面)
<%@ page contentType="text/html; charset=GB2312" %>
<%@ page import = "java.sql.*" %>

<%
response.setContentType("text/html; charset=GB2312");
request.setCharacterEncoding("GB2312");

int id = Integer.parseInt(request.getParameter("id"));//获取传过来的ID
String title, userName, email, textmain, lasttime, sql;

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn = DriverManager.getConnection("jdbc:odbc:BBSDSN");
Statement st = cn.createStatement();
sql = "select * from BBS_TEXT where ID=" + id;
ResultSet rs = st.executeQuery(sql);

rs.next();
title = rs.getString("TITLE");
userName = rs.getString("USERNAME");
email = rs.getString("EMAIL");
textmain = rs.getString("TEXTMAIN");
lasttime = rs.getString("LASTTIME");

out.print("<html>");
out.print("<head>");

out.print("<script language=JavaScript>");
out.print("function checkform(formbackCall)");
out.print("{");
out.print("var flag = true;");
out.print("if(formbackCall.txtbackCall.value == \"\" || formbackCall.txtbackCall.value == null)");
out.print("{");
out.print("alert(\"回复内容不能为空!\");");
out.print("formbackCall.txtbackCall.focus();");
out.print("flag = false;");
out.print("}");
out.print("return flag;");
out.print("}");
out.print("</script>");

out.print("<title>阿当论坛--回复帖子</title>");
out.print("</head>");
out.print("<body bgcolor=#CCFFFF>");
out.print("<center>");
out.print("<table border=0 width=80% bordercolor=#000000 bordercolordark=#FFFFFF>");

out.print("<tr>");
out.print("<td align=left>");
out.print("<font face=宋体 size=1><b>主题:</b>&nbsp;" + title);
out.print("</font>");
out.print("</td>");
out.print("</tr>");

out.print("<tr>");
out.print("<td align=left>");
out.print("<font face=宋体 size=1><b>作者:</b>&nbsp;&nbsp;" + userName + "</font>");
out.print("</td>");
out.print("</tr>");

out.print("<tr>");
out.print("<td align=left>");
out.print("<font face=宋体 size=1><b>作者信箱:</b>&nbsp;" + email + "</font>");
out.print("</td>");
out.print("</tr>");

out.print("<tr>");
out.print("<td align=left>");
out.print("<font face=宋体 size=1><b>发贴时间:</b>&nbsp;" + lasttime + "</font>");
out.print("</td>");
out.print("</tr>");

out.print("<tr>");
out.print("<td>");
out.print("<font face=宋体 size=1><b>正文内容:</b><br>" + textmain + "</font>");
out.print("</td>");
out.print("</tr>");

out.print("<tr><td><hr></td></tr>");

sql = "select USERNAME,EMAIL,TEXTMAIN,LASTTIME from BBS_TEXT where ROOTID=" + id;
rs = st.executeQuery(sql);
int count = 1;
while(rs.next())
{
userName = rs.getString("USERNAME");
email = rs.getString("EMAIL");
textmain = rs.getString("TEXTMAIN");
lasttime = rs.getString("LASTTIME");

out.print("<tr>");
out.print("<td>");
out.print("<font face=宋体 size=1><b>回复者:</b>&nbsp;" + userName + "</font>");
out.print("</td>");
out.print("</tr>");

out.print("<tr>");
out.print("<td>");
out.print("<font face=宋体 size=1><b>回复者邮箱:</b>&nbsp;" + email + "</font>");
out.print("</td>");
out.print("</tr>");

out.print("<tr>");
out.print("<td>");
out.print("<font face=宋体 size=1><b>回复时间:</b>&nbsp;" + lasttime + "</font>");
out.print("</td>");
out.print("</tr>");

out.print("<tr>");
out.print("<td>");
out.print("<font face=宋体 size=1><b>回复内容:<p/></b>" + textmain + "</font>");
out.print("</td>");
out.print("</tr>");

out.print("<tr>");
out.print("<td align=right>");
out.print("<font face=宋体 size=1>第<font face=宋体 size=2 color=red>" + count + "</font>楼</font>");
out.print("</td>");
out.print("</tr>");
count++;
out.print("<tr><td><hr></td></tr>");
}
out.print("</table>");
out.print("</center>");

out.print("<form method='POST' action='checkbackCall.jsp' name='formbackCall' onsubmit=\"return checkform(this)\">");
out.print("<center>");
out.print("<table border=0 width=80% bordercolor=#000000 bordercolordark=#FFFFFF>");
out.print("<tr>");
out.print("<td align=center>");
out.print("<font face=宋体 size=1><b>回复:</b></font><br>");
out.print("<TEXTAREA NAME=txtbackCall ROWS=5 COLS=70></TEXTAREA>");
out.print("<INPUT TYPE=hidden name=id value=" + id + ">"); //用隐藏域将ID传到检测页面
out.print("</td>");
out.print("</tr>");
out.print("<tr>");
out.print("<td align=center>");
out.print("<INPUT TYPE=submit value='回复'>&nbsp;&nbsp;<INPUT TYPE=reset value='重写'>");
out.print("</td>");
out.print("</tr>");
out.print("<tr><td align=center><font face=宋体 size=1><a href=bbsmain.jsp><br>返回到论坛主页</a></font></td></tr>");
out.print("</table>");
out.print("</center>");
out.print("</form>");
out.print("</body>");
out.print("</html>");

rs.close();
st.close();
cn.close();
}
catch(Exception e)
{
e.printStackTrace();
}
%>


学好编程就能编出自己的未来! 加油!自信!努力!奋斗!
2006-07-15 10:37
神vLinux飘飘
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:浙江杭州
等 级:贵宾
威 望:91
帖 子:6140
专家分:217
注 册:2004-7-17
得分:0 
汗啊,当当怎么从C板块流窜到这里来作案了~~
把你的程序打包一下吧

淘宝杜琨
2006-07-15 10:43
当当
Rank: 1
等 级:新手上路
帖 子:235
专家分:0
注 册:2004-4-30
得分:0 
我怎么不能跟贴了.还有一个文件源码,想请问TEXTAREA文本域中的字体怎样设置.没有学JAVABEN,所以暂时只能做成这样了.这个简易论坛暂时只能发贴,与回复贴,呵呵,是不是太简易了点啊,请大家不要见^○^.

[此贴子已经被作者于2006-7-15 10:52:06编辑过]



学好编程就能编出自己的未来! 加油!自信!努力!奋斗!
2006-07-15 10:45



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-78424-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.061638 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved