基于javaweb+JSP+Servlet个人日记管理系统
开发工具:eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
/**
* @see HttpServlet#HttpServlet()
*/
public DailyAddServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setCharacterEncoding("utf-8");
HttpSession session = request.getSession();
User user = (User)session.getAttribute("user");
String dailyJson = request.getParameter("daily");
JSONObject jsonObject = JSON.parseObject(dailyJson);
String title = jsonObject.getString("title");
String context = jsonObject.getString("context");
String records = jsonObject.getString("records");
String type = jsonObject.getString("type");
Daily daily = new Daily();
daily.setTitle(title);
daily.setContext(context);
daily.setUid(user.getUid());
daily.setRecords(records);
daily.setType(type);
DailyService dailyService = new DailyServiceImpl();
int result = dailyService.insertDaily(daily);
Map<String,Object> map = new HashMap<>();
if(result>0) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = Util.getConn();
StringBuffer sql = new StringBuffer("select did,title,context,pic,uid,recorded,createtime,`type` from daily ");
keyword = keyword != null && !keyword.trim().equals("") ? keyword : "";
sql.append(" where (title like '%" + keyword + "%' or context like '%" + keyword + "%' or recorded like '%" + keyword + "%')");
if (start != null && end != null && !start.trim().equals("") && !end.trim().equals("")) {
sql.append(" and DATE_FORMAT(createtime,'%Y-%m-%d')>='" + start.trim() + "' and DATE_FORMAT(createtime,'%Y-%m-%d')<='" + end.trim() + "'");
}
sql.append("limit ?,?");
ps = conn.prepareStatement(sql.toString());
ps.setInt(1, (pageIndex - 1) * pageSize);
ps.setInt(2, pageSize);
rs = ps.executeQuery();
while (rs.next()) {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
HttpSession session = request.getSession();
User user = (User)session.getAttribute("user");
String dailyJson = request.getParameter("daily");
JSONObject jsonObject = JSON.parseObject(dailyJson);
String title = jsonObject.getString("title");
String context = jsonObject.getString("context");
String records = jsonObject.getString("records");
var daily = "{\"title\":\"" + title + "\",\"context\":\"" + context + "\",\"type\":\"" + type + "\",\"uid\":\"" + uid + "\",\"records\":\"" + records + "\",\"did\":\"" + did + "\"}";
console.log(daily);
$.ajax({
type: "POST",
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
url: "dailyUpdateServlet",
dataType: 'json',
data: {"daily": daily},
success: function (result) {
console.log("success");
if (result.code == 0) {
alert(result.msg);
top.location.href = "dailyListServlet";
}
if (result.code == 500) {
alert(result.msg);
box-shadow: 0px 0px 0px #333333;
top: 50%;
left: 50%;
margin-top: -250px;
margin-left: -175px;
transition: all 1s;
-moz-transition: all 1s; /* Firefox 4 */
-webkit-transition: all 1s; /* Safari 和 Chrome */
-o-transition: all 1s; /* Opera */
}
.login-top {
font-size: 24px;
margin-top: 80px;
padding-left: 40px;
box-sizing: border-box;
color: #333333;
margin-bottom: 50px;
}
<input name="uid" id="uid" type='hidden' value="${descDaily.uid}">
<input name="did" id="did" type='hidden' value="${descDaily.did}">
<div class="layui-form-item">
<label for="title" class="layui-form-label"> <span
class="x-red">*span>标题:
label>
<div class="layui-input-inline">
<input type="text" id="title" name="title" required
autocomplete="off" class="layui-input" value="${descDaily.title }">
div>
<select id="type" name="type">
<%-- <option if test="${'生活'==descDaily.type}">selectedc:if>>生活option>
<option if test="${'电影'==descDaily.type}">selectedc:if>>电影option>
<option if test="${'音乐'==descDaily.type}">selectedc:if>>音乐option>
<option if test="${'读书'==descDaily.type}">selectedc:if>>读书option>
<option if test="${'学习'==descDaily.type}">selectedc:if>>学习option>--%>
<option value="生活">生活option>
<option value="电影">电影option>
<option value="音乐">音乐option>
<option value="读书">读书option>
<option value="学习">学习option>
this.pic = pic;
this.uid = uid;
this.type = type;
}
public int getDid() {
return did;
}
public String getType() {
return type;
}
public void setType(String type) {
}
});
//监听提交
form.on('submit(add)', function(data){
console.log(data);
//发异步,把数据提交给php
layer.alert("增加成功", {icon: 6},function () {
// 获得frame索引
var index = parent.layer.getFrameIndex(window.name);
//关闭当前frame
parent.layer.close(index);
});
return false;
});
});
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import cn.demo.vo.Daily;
import cn.demo.vo.User;
import cn.demo.service.DailyService;
import cn.demo.service.impl.DailyServiceImpl;
@WebServlet("/dailyAddServlet")
public class DailyAddServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public DailyAddServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
map.put("count", 0);
}else {
map.put("code", 500);
map.put("msg", "服务器异常,删除失败");
map.put("count", 0);
}
out.print(JSON.toJSON(map));
out.close();
}
}
package cn.demo.servlet;
return 0;
}
public static void close(Connection conn, Statement st, ResultSet rs) {
try {
if (rs != null) {
rs.close();
}
if (st != null) {
st.close();
}
if (conn != null) {
conn.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
package cn.demo.servlet;
import cn.demo.vo.User;
}
return dailyList;
}
@Override
public List<Daily> getAllDailyByPage(int pageIndex, int pageSize, String keyword, String start, String end) {
List<Daily> dailyList = new ArrayList<Daily>();
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = Util.getConn();
<head>
<meta charset="UTF-8">
<title>欢迎页面-生活点滴记录系统title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="./css/font.css">
<link rel="stylesheet" href="./css/xadmin.css">
<script type="text/javascript" src="./js/jquery-3.1.1.js">script>
<script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8">script>
<script type="text/javascript" src="./js/xadmin.js">script>
<style>
td div{
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
while (rs.next()) {
Daily daily = new Daily();
daily.setDid(rs.getInt(1));
daily.setTitle(rs.getString(2));
daily.setContext(rs.getString(3));
daily.setPic(rs.getString(4));
daily.setUid(rs.getInt(5));
daily.setRecords(rs.getString(6));
daily.setCreatetime(rs.getDate(7));
dailyList.add(daily);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
Util.close(conn, ps, rs);
}
return dailyList;
}
@Override
public List<Daily> getAllDailyByPage(int pageIndex, int pageSize, String keyword, String start, String end) {
List<Daily> dailyList = new ArrayList<Daily>();
transition: all 0.5s;
padding-left: 10px;
color: #333333;
width: 100%;
height: 30px;
border: 0;
border-bottom: 1px solid #cccccc;
border-top: 1px solid #ffffff;
border-left: 1px solid #ffffff;
border-right: 1px solid #ffffff;
box-sizing: border-box;
outline: none;
position: relative;
}
.login-center-input input:focus {
border: 1px solid dodgerblue;
}
.login-center-input input:focus ~
.login-center-input-text {
top: 0;
z-index: 3;
opacity: 1;
}
public void setContext(String context) {
this.context = context;
}
public Date getCreatetime() {
return createtime;
}
public void setCreatetime(Date createtime) {
<meta charset="UTF-8">
<title>后台管理-生活点滴记录系统title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
<link rel="stylesheet" href="./css/font.css">
<link rel="stylesheet" href="./css/xadmin.css">
<script type="text/javascript" src="./js/jquery-3.1.1.js">script>
<script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8">script>
<script type="text/javascript" src="./js/xadmin.js">script>
}else{
$(obj).attr('title','启用')
$(obj).find('i').html('');
$(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
layer.msg('已启用!',{icon: 5,time:1000});
}
});
}
/*用户-删除*/
function member_del(obj,id){
layer.confirm('确认要删除吗?',function(index){
//发异步删除数据
$.ajax({
method:"post",
url:"dailyDelServlet",
data:{"delId":id},
success:function(data){
//
}
});
$(obj).parents("tr").remove();
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
<link rel="stylesheet" href="./css/font.css">
<link rel="stylesheet" href="./css/xadmin.css">
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js">script>
<style>
img {
width: 200px;
height: 200px;
border: 1px solid whitesmoke;
background-color: white;
cursor: pointer;
}
.layui-upload {
display: inline-block;
}
.layui-form-label {
width: 90px;
}
script>
body>
html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>生活点滴记录系统title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
<link rel="stylesheet" href="./css/font.css">
<link rel="stylesheet" href="./css/xadmin.css">
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js">script>
<style>
return true;
}
script>
html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
public String getPic() {
return pic;
}
public void setPic(String pic) {
this.pic = pic;
}
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
public String getRecords() {
return records;
}
public void setRecords(String records) {
this.records = records;
}
div>
<div class="layui-form-item">
<label class="layui-form-label">总结:label>
<div class="layui-input-block">
<input type="text" name="records" id="records" required
autocomplete="off" class="layui-input" value="${descDaily.records }">
div>
div>
<div class="layui-form-item">
<button class="layui-btn" lay-filter="add" id="recordbutton" name="recordbutton" lay-submit="">修改button>
div>
div>
<script>
$(function () {
$("#recordbutton").click(function () {
var uid = $('#uid').val();
var did = $('#did').val();
var title = $('#title').val();
运行环境
Java≥6、Tomcat≥7.0、MySQL≥5.5
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
技术框架
JSP Servlet MySQL CSS JavaScript layui
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
个人日记的增删改查管理