基于javaweb+JSP+Servlet校园论坛校园BBS(管理员、用户)
开发工具:eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
return userid.test(str);
}
function isEmail(str){
var email=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-]{2,3})+\.([a-zA-Z0-9_-]{2,3})+/;
return email.test(str);
}
function isPhone(str){
var phone=/^([0-9])+/;
return phone.test(str);
}
function check_login(form1){
var user_id=document.getElementById("userid").value
var user_name=document.getElementById("username").value;
var user_password=document.getElementById("userpassword").value;
var confirmPwd=document.getElementById("confirmPwd").value;
alert("两次密码不一致!请重新输入!");
return false;
}
// user_password=hex_md5(document.forms.form1.user_password.value);
user_password = document.forms.form1.user_password.value;
document.forms.form1.md5Pwd.value=user_password;
//if(document.forms.form1.user_phone.value==""){
// alert("联系电话不能为空!");
//document.forms.form1.user_phone.focus();
//return false;
//}
//if(document.forms.form1.user_email.value==""){
// alert("电子邮箱不能为空!");
// document.forms.form1.user_email.focus();
// return;
//}
if(!isPhone(document.getElementById("phone").value)){
alert("电话格式不正确!");
nav>
div>
body>
html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.demo.entity.*"%>
DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
// document.forms.form1.user_id.focus();
// return false;
//}
if(!isUserId(user_id)){
alert("学号应为纯数字");
document.getElementById("userid").focus();
return false;
}
if(user_name==""){
alert("请输入用户名!");
document.getElementById("username").focus();
return false;
}
if(user_password==""){
}
}
%>
table>
div>
div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
发帖
h3>
div>
<div class="panel-body">
<form class="form-horizontal" role="form" name="form1" method="post" action="release">
forum.setFid(rs.getInt(1));
forum.setTitle(rs.getString(2));
forum.setContent(rs.getString(3));
forum.setCreateTime(rs.getTimestamp(4));
//获取对应用户表中的外键
UserEntity author = new UserEntity();
author.setUser_id(rs.getInt(5));
forum.setAuthor(author);
list.add(forum);
System.out.println("查询所有帖子:"+rs.getString(3));
}
}catch(Exception e){
e.printStackTrace();
}finally{
Util.close(rs, ps, conn);
}
return list;
<div class="col-sm-4">
<div>
<img src="${pageContext.request.contextPath}/images/userface/user01.jpg" width="70" height="70" id="idface">
div>
<select class="form-control" placeholder=".col-lg-4" name="user_face" onchange="document.images['idface'].src=options[selectedIndex].value;">
<option value="${pageContext.request.contextPath}/images/userface/user01.jpg" selected>user1option>
<option value="${pageContext.request.contextPath}/images/userface/user03.jpg">user2option>
<option value="${pageContext.request.contextPath}/images/userface/user04.jpg">user3option>
<div>
<ul class="nav nav-tabs">
<li class="active"><a href="#home" data-toggle="tab">Homea>li>
ul>
div>
<div class="tab-pane fade in active" id="home">
<div class="panel panel-default">
<div class="panel-body">
<table class="table table-hover">
<thead>
<tr>
<th>标题th>
<th>时间th>
<th>发帖人th>
tr>
thead>
style>
head>
<body class="bk">
<div class="container">
<nav class="navbar " role="navigation">
<h3>用户修改h3>
<form class="form-horizontal" name="form1" method="post" action="${pageContext.request.contextPath}/UserUpdateInfo">
<div class="form-group">
<label class="col-sm-2 control-label">学号:label>
<div class="col-sm-4">
<input class="form-control" type="text" name="user_id" value="${user.user_id}" readonly="readonly" >
div>div>
<div class="form-group">
<label class="col-sm-2 control-label">用户名:label>
<div class="col-sm-4">
<input class="form-control" id="user_name" type="text" name="user_name" placeholder="请输入用户名...">
div>div>
if(!isPhone(document.getElementById("phone").value)){
alert("电话格式不正确!");
document.getElementById("phone").focus();
return false;
}
if(!isEmail(document.getElementById("email").value)){
alert("邮箱格式不正确!");
document.getElementById("email").focus();
return false;
}
if(document.forms.form1.user_from.value==""){
alert("请输入地址!");
document.forms.form1.user_from.focus();
return false;
a>td>
tr>
tbody>
<%
}
}
%>
table>
div>
div>
if(confirmPwd==""){
alert("请确认密码!");
document.forms.form1.confirmPwd.focus();
return false;
}
if(user_password!=confirmPwd){
alert("两次密码不一致!请重新输入!");
return false;
}
public ForumEntity findForumById(int fid) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
ForumEntity forum = null;
String sql = "select * from forum_info where fid = ?";
try{
conn = Util.getConnection();
ps = conn.prepareStatement(sql);
ps.setInt(1, fid);
rs = ps.executeQuery();
if(rs.next()){
forum = new ForumEntity();
forum.setFid(rs.getInt(1));
forum.setTitle(rs.getString(2));
forum.setContent(rs.getString(3));
conn = Util.getConnection();
ps = conn.prepareStatement(sql);
ps.setString(1, forum.getTitle());
ps.setString(2, forum.getContent());
ps.setTimestamp(3, forum.getCreateTime());
ps.setInt(4, forum.getAuthor().getUser_id());
i = ps.executeUpdate();
}catch(Exception e){
e.printStackTrace();
}finally{
Util.close(null, ps, conn);
}
return i;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.demo.entity.ForumEntity;
import com.demo.service.impl.BbsServiceImpl;
import com.demo.service.BbsServiceInf;
@SuppressWarnings("serial")
public class UPersonForumListServlet extends HttpServlet {
public void service (HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
String user_id=request.getParameter("uid");
if(user_id==null){
String uid=(String)request.getAttribute("uid");
int pid=Integer.parseInt(uid);
BbsServiceInf service=new BbsServiceImpl();
List<ForumEntity> personList=new ArrayList<ForumEntity>();
conn= Util.getConnection();
ps=conn.prepareStatement(sql);
ps.setInt(1, pid);
rs=ps.executeQuery();
while(rs.next()){
ForumEntity forum=new ForumEntity();
forum.setFid(rs.getInt(1));
forum.setTitle(rs.getString(2));
forum.setContent(rs.getString(3));
forum.setCreateTime(rs.getTimestamp(4));
UserEntity user=new UserEntity();
user.setUser_id(rs.getInt(5));
forum.setAuthor(user);
list.add(forum);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
div>
div>
form>nav>div>
body>
<script type="text/javascript" src="js/md5.js">script>
html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="css/background.css" />
// document.forms.form1.user_id.focus();
// return false;
//}
if(!isUserId(user_id)){
alert("学号应为纯数字");
document.getElementById("userid").focus();
return false;
}
if(user_name==""){
alert("请输入用户名!");
document.getElementById("username").focus();
return false;
}
}
if(user_password==""){
alert("请输入密码!");
document.forms.form1.user_password.focus();
return;
}
if(confirmPwd==""){
alert("请确认密码!");
document.forms.form1.confirmPwd.focus();
return;
}
if(user_password!=confirmPwd){
}
if(!isEmail(document.getElementById("email").value)){
alert("邮箱格式不正确!");
document.getElementById("email").focus();
return false;
}
if(document.forms.form1.user_from.value==""){
alert("请输入地址!");
document.forms.form1.user_from.focus();
return false;
}
if(inputCode==""){
alert("请输入验证码!");
document.forms.form1.inputCode.focus();
return false;
}
public List<UserEntity> findUserlist(){
Connection conn=null;
PreparedStatement ps=null;
ResultSet rs=null;
List<UserEntity> userlist=new ArrayList<UserEntity>();
String sql="select * from user_info";
try {
conn= Util.getConnection();
ps=conn.prepareStatement(sql);
rs=ps.executeQuery();
while(rs.next()){
UserEntity user=new UserEntity();
user.setUser_id(rs.getInt(1));
user.setUser_name(rs.getString(2));
ps.setInt(1, fid);
ps.executeUpdate();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
Util.close(null, ps, conn);
}
}
//根据帖子id删除所有回复
public void deleteReply(int fid){
System.out.println(fid);
Connection conn=null;
PreparedStatement ps=null;
String sql="delete from reply_info where fid=?";
try {
conn= Util.getConnection();
ps=conn.prepareStatement(sql);
ps.setInt(1, fid);
out.print(html);
}
out.flush();
out.close();
}
}
package com.demo.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
div>
div>
<a class="carousel-control left" href="#myCarousel"
data-slide="prev">‹a>
<a class="carousel-control right" href="#myCarousel"
data-slide="next">›a>
div>
div>
<div class="container">
<nav class="navbar navbar-default" role="navigation">
<div>
<img src="images/logo.png" class="img-circle">
div>
<div>
<ul class="nav nav-tabs">
<li class="active"><a href="#home" data-toggle="tab">Homea>li>
ps = conn.prepareStatement(sql);
ps.setInt(1, user.getUser_id());
ps.setString(2, user.getUser_name());
ps.setString(3, user.getUser_password());
ps.setString(4, user.getUser_sex());
ps.setString(5, user.getUser_face());
ps.setString(6, user.getUser_phone());
ps.setString(7, user.getUser_email());
ps.setString(8, user.getUser_from());
i = ps.executeUpdate();
System.out.println("插入数据库成功");
}catch(Exception e){
e.printStackTrace();
}finally{
request.setAttribute("perForumList", personList);
request.getRequestDispatcher("page/user/myforum.jsp").forward(request, response);
}
// PrintWriter out=response.getWriter();
// out.println(user_id);
// out.println(user_id);
}
}
package com.demo.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
运行环境
Java≥6、Tomcat≥7.0、MySQL≥5.5
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
技术框架
CSS JavaScript jQuery JSP Servlet JDBC MySQL
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
管理员:登录、注册、发贴、回复、用户管理、帖子管理等
用户:登录、注册、发贴、回复
用户
管理员