1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ page
import="java.text.SimpleDateFormat,koi.StringUtil"%>
<%@ include file="/header.jsp"%>
<jsp:useBean id="guestbook" class="koi.Guestbook"></jsp:useBean>
<jsp:useBean id="mysqlutil" class="koi.MySQLUtil"></jsp:useBean>
<jsp:setProperty property="*" name="guestbook"/>
<%
int result = 0;
// 设置编码
request.setCharacterEncoding("utf-8");
// 要执行的SQL语句
String sql = "insert into book(name,email,phone,title,content,publishtime) values(?,?,?,?,?,?)";
String name = guestbook.getName();
String email = guestbook.getEmail();
String phone = guestbook.getPhone();
String topic = guestbook.getTopic();
String content = guestbook.getContent();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Object[] param = { name, email, phone, topic, content, sdf.format(new java.util.Date()) };
mysqlutil.setDataSourceName("java:/comp/env/jdbc/mysql");
mysqlutil.init();
result = mysqlutil.update(sql, param);
response.getWriter().append(Integer.toString(result));
%>
<%@ include file="/footer.jsp"%>
|