jsp+servlet+mysql留言web程序大作业分享
不是特别美观,完成作业还是足够的。
有问题可以联系我:QQ2039808149
完整源代码下载地址:
https://download.csdn.net/download/weixin_43960044/11057955
登录页面:
登录界面源代码:
<%@ 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=ISO-8859-1">
<title>Insert title here</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<%
Boolean yanzheng = true;
if(!yanzheng){
HttpSession session1 = request.getSession();
yanzheng = (Boolean)session.getAttribute("yanzheng");
System.out.println(yanzheng);
}
/*
HttpSession session1 = request.getSession();
yanzheng = (Boolean)session.getAttribute("yanzheng");
System.out.println(yanzheng);
*/
%>
<h1>Goss微博</h1>
<div class="element">
<div class="element-left">
<div class="profile">
<div class="profile-follow">
<ul>
<li style="color: white; font-size: 26px; margin-top: -15px;">用户登录</li>
</ul>
</div>
<div class="login-top">
<form method="post" action="land">
用户名:<input type="text" name="username"><br>
密码:<input type="password" name="password">
<%
if(!yanzheng){
out.print("<div><li>账号或者密码错误!</li></div>");
}
%>
<div class="login-bottom">
<ul>
</ul>
<ul>
<li><a href="#">忘记密码</a></li>
<li>
<input type="submit" value="登录">
<a href="regist.html"><input type="button" value="注册"></a>
</li>
</ul>
</div>
</form>
<div class="clear"></div>
</div>
</div>
</div>
</div>
</body>
</html>
留言界面:
留言界面源代码:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ page import="java.sql.ResultSet, java.sql.SQLException, Connector.DataBaseOperate" %>
<!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">
<title>My Widget</title>
<link rel="stylesheet" href="./liuyan_files/style.css" type="text/css">
</head>
<%
DataBaseOperate da = new DataBaseOperate();
ResultSet rs = da.query("SELECT * FROM contenttable order by data desc");
System.out.println("执行");
%>
<body>
<div class="element">
<div class="element-left">
<div class="profile">
<div class="profile-top">
<div class="profile-text">
<div class="profile-img"><img src="./liuyan_files/b1.jpg" alt=""></div>
<div class="profile-text1">
<h4><%out.print(session.getAttribute("username1")); %></h4>
<a href="http://localhost:8080/webshiyan1/index.jsp"><i></i>注销</a>
</div>
<div class="clear"></div>
</div>
<div class="login-top">
<form method="post" action="liuyan">
分享新鲜事...<br>
<textarea cols="50" rows="4" name="content"></textarea>
<br>
<button type="submit">送出</button>
</form>
<table style="text-align: left; width: 460px; height: 88px;" border="0" cellpadding="2"
cellspacing="2">
<tbody>
<tr>
<td style="vertical-align:top;">
<%while(rs.next()){ %>
<%out.print("<tr><td>"); %>
<%out.print(rs.getString(4)); %>
<%out.print(rs.getString(1)+"<br>"); %>
<%out.print(rs.getString(2)); %>
<%String lianjie= "http://localhost:8080/webshiyan1/deleteliuyan?message=" + rs.getString(3); %>
<%out.print("<a href=" + lianjie + ">删除</a>"); %>
<%out.print("<hr>"); %>
<%out.print("</tr></td>"); %>
<%} %>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
mysql数据库:
/*
Navicat MySQL Data Transfer
Source Server : localhost
Source Server Version : 50027
Source Host : localhost:3306
Source Database : liuyan
Target Server Type : MYSQL
Target Server Version : 50027
File Encoding : 65001
Date: 2019-03-25 14:35:33
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `contenttable`
-- ----------------------------
DROP TABLE IF EXISTS `contenttable`;
CREATE TABLE `contenttable` (
`data` char(100) default NULL,
`content` char(100) default NULL,
`id` int(20) NOT NULL auto_increment,
`username` char(100) default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of contenttable
-- ----------------------------
INSERT INTO `contenttable` VALUES ('2019-03-16 18:13:20', '你好呀!', '3', 'test');
INSERT INTO `contenttable` VALUES ('2019-03-16 18:13:34', '这里是留言程序!', '4', 'test');
-- ----------------------------
-- Table structure for `user`
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`username` char(20) NOT NULL,
`password` char(30) NOT NULL,
`email` char(30) NOT NULL,
PRIMARY KEY (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES ('test', '123', '[email protected]');