You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
library_manage_system/WebContent/reader/14messageSub.jsp

83 lines
2.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<%@ page import="java.sql.*" %> <!-- 导入Java SQL包用于数据库操作 -->
<%@ page import="java.util.*" %> <!-- 导入Java工具包包含日期时间类等 -->
<%@ page import="javabean.DateTime"%> <!-- 导入自定义的DateTime类 -->
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%> <!-- 设置页面语言为Java内容类型和字符编码为UTF-8 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <!-- 定义HTML文档类型 -->
<html>
<head>
<meta charset="utf-8"> <!-- 设置字符编码为UTF-8 -->
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <!-- 设置IE浏览器兼容模式 -->
<meta name="viewport" content="width=device-width, initial-scale=1"> <!-- 设置视口宽度和初始缩放比例 -->
<title></title> <!-- 页面标题 -->
<!-- Bootstrap CSS文件 -->
<link href="../css/bootstrap.min.css" rel="stylesheet">
<!-- jQuery库Bootstrap的所有JavaScript插件都依赖jQuery所以必须放在前边 -->
<!-- 自定义CSS文件 -->
<link rel="stylesheet" id="templatecss" type="text/css" href="../public/css/message.css">
</head>
<body>
<!-- 使用JSP标签声明一个JavaBean对象msg作用域为session类为javabean.JDBCBean -->
<jsp:useBean id="msg" scope="session" class="javabean.JDBCBean"></jsp:useBean>
<%
// 创建DateTime对象实例
DateTime date = new DateTime();
// 获取当前时间字符串
String time = date.show();
// 从请求中获取参数msg的值
String mes = request.getParameter("msg");
try {
// 从session中获取reader属性并转换为字符串
String card = session.getAttribute("reader").toString();
// 构建SQL插入语句
String sql = "insert into message(card_id,detail,public_date)values('" + card + "','" + mes + "','" + time + "');";
// 检查card和mes是否不为空且mes不为空白字符串
if (card != null && mes != null && !mes.trim().equals("")) {
// 执行SQL插入操作
int i = msg.executeUpdate(sql);
// 根据插入结果进行跳转
if (i == 1) {
%>
// 这是用户提交留言后的处理逻辑
<script>
alert('留言成功!');
window.location.href = "15checkMessage.jsp";//将当前浏览器窗口重定向到指定的jsp
</script>
<%
}
else {
%>
<script>
alert('留言未成功!');
window.location.href = "13message.jsp";
</script>
<%
}
} else {
%>
<script>
alert('留言未成功!留言不能为空!');
window.location.href = "13message.jsp";
</script>
<%
}
%>
<%
}catch(Exception e){
%>
<script>
alert('留言未成功!请先登录!');
window.location.href = "06borrowBooks.jsp";
</script>
<%
}
%>
</body>
</html>