?? taskservice.jsp
字號(hào):
conn = DBUtils.getConnection(); //獲取數(shù)據(jù)庫連接
pstmt = conn.prepareStatement(sql1);//根據(jù)sql1創(chuàng)建PreparedStatement
pstmt.setString(1, userId); //設(shè)置參數(shù)
pstmt.setString(2, listId); //設(shè)置參數(shù)
pstmt.executeUpdate(); //執(zhí)行刪除
pstmt.close(); //關(guān)閉
pstmt = conn.prepareStatement(sql2);//根據(jù)sql2創(chuàng)建PreparedStatement
pstmt.setString(1, userId); //設(shè)置參數(shù)
pstmt.setString(2, listId); //設(shè)置參數(shù)
pstmt.executeUpdate(); //執(zhí)行刪除
} catch (SQLException e) {
System.out.println(e.toString());
} finally {
DBUtils.close(pstmt); //關(guān)閉PreparedStatement
DBUtils.close(conn); //關(guān)閉連接
}
}
//更新任務(wù)列表
void updateList(String userId, String listId, String listName) {
String sql = "update task_lists set listname = ? where userid = ? and id = ?"; //定義SQL語句
Connection conn = null; //聲明Connection對(duì)象
PreparedStatement pstmt = null; //聲明PreparedStatement對(duì)象
try {
conn = DBUtils.getConnection(); //獲取數(shù)據(jù)庫連接
pstmt = conn.prepareStatement(sql); //根據(jù)sql創(chuàng)建PreparedStatement
pstmt.setString(1, listName); //設(shè)置參數(shù)
pstmt.setString(2, userId); //設(shè)置參數(shù)
pstmt.setString(3, listId); //設(shè)置參數(shù)
pstmt.executeUpdate(); //執(zhí)行更新
} catch (SQLException e) {
System.out.println(e.toString());
} finally {
DBUtils.close(pstmt); //關(guān)閉PreparedStatement
DBUtils.close(conn); //關(guān)閉連接
}
}
//添加任務(wù)
void addTask(String userId, String listId, String taskName) {
String sql = "insert into task_tasks(userid, listid, taskname) values(?,?,?)"; //定義SQL語句
Connection conn = null; //聲明Connection對(duì)象
PreparedStatement pstmt = null; //聲明PreparedStatement對(duì)象
try {
conn = DBUtils.getConnection(); //獲取數(shù)據(jù)庫連接
pstmt = conn.prepareStatement(sql); //根據(jù)sql創(chuàng)建PreparedStatement
pstmt.setString(1, userId); //設(shè)置參數(shù)
pstmt.setString(2, listId); //設(shè)置參數(shù)
pstmt.setString(3, taskName); //設(shè)置參數(shù)
pstmt.executeUpdate(); //執(zhí)行插入
} catch (SQLException e) {
System.out.println(e.toString());
} finally {
DBUtils.close(pstmt); //關(guān)閉PreparedStatement
DBUtils.close(conn); //關(guān)閉連接
}
}
//刪除任務(wù)
void delTask(String userId, String taskId) {
String sql = "delete from task_tasks where userid = ? and id = ?"; //定義SQL語句
Connection conn = null; //聲明Connection對(duì)象
PreparedStatement pstmt = null; //聲明PreparedStatement對(duì)象
try {
conn = DBUtils.getConnection(); //獲取數(shù)據(jù)庫連接
pstmt = conn.prepareStatement(sql); //根據(jù)sql創(chuàng)建PreparedStatement
pstmt.setString(1, userId); //設(shè)置參數(shù)
pstmt.setString(2, taskId); //設(shè)置參數(shù)
pstmt.executeUpdate(); //執(zhí)行刪除
} catch (SQLException e) {
System.out.println(e.toString());
} finally {
DBUtils.close(pstmt); //關(guān)閉PreparedStatement
DBUtils.close(conn); //關(guān)閉連接
}
}
//更新任務(wù)
void updateTask(String userId, String taskId, String taskName) {
String sql = "update task_tasks set taskname = ? where userid = ? and id = ?"; //定義SQL語句
Connection conn = null; //聲明Connection對(duì)象
PreparedStatement pstmt = null; //聲明PreparedStatement對(duì)象
try {
conn = DBUtils.getConnection(); //獲取數(shù)據(jù)庫連接
pstmt = conn.prepareStatement(sql); //根據(jù)sql創(chuàng)建PreparedStatement
pstmt.setString(1, taskName); //設(shè)置參數(shù)
pstmt.setString(2, userId); //設(shè)置參數(shù)
pstmt.setString(3, taskId); //設(shè)置參數(shù)
pstmt.executeUpdate(); //執(zhí)行更新
} catch (SQLException e) {
System.out.println(e.toString());
} finally {
DBUtils.close(pstmt); //關(guān)閉PreparedStatement
DBUtils.close(conn); //關(guān)閉連接
}
}
%>
<%
out.clear(); //清空當(dāng)前的輸出內(nèi)容(空格和換行符)
request.setCharacterEncoding("UTF-8"); //設(shè)置請(qǐng)求字符集為UTF-8
String userId = (String) session.getAttribute(sessionKey); //獲取當(dāng)前登錄用戶編號(hào)
String action = request.getParameter("action"); //獲取title
//根據(jù)action參數(shù)不同執(zhí)行不同的操作
if ("login".equals(action)) { //登錄操作
String userName = request.getParameter("userName");
String password = request.getParameter("password");
String result = login(userName, password, session);
out.print(result);
} else if ("logout".equals(action)) { //退出操作
session.removeAttribute(sessionKey);
} else if ("getLists".equals(action)) { //獲取任務(wù)列表
out.print(getLists(userId));
} else if ("getTasks".equals(action)) { //獲取任務(wù)
String listId = request.getParameter("listId");
out.print(getTasks(userId, listId));
} else if ("changeTaskStatus".equals(action)) { //改變?nèi)蝿?wù)狀態(tài)
String taskId = request.getParameter("taskId");
String status = request.getParameter("status");
changeTaskStatus(userId, taskId, status);
out.print("任務(wù)狀態(tài)修改成功。");
} else if ("addList".equals(action)) { //添加任務(wù)列表
String listName = request.getParameter("listName");
addList(userId, listName);
out.print("列表添加成功。");
} else if ("delList".equals(action)) { //刪除任務(wù)列表
String listId = request.getParameter("listId");
delList(userId, listId);
out.print("列表刪除成功。");
} else if ("updateList".equals(action)) { //更新任務(wù)列表
String listId = request.getParameter("listId");
String listName = request.getParameter("listName");
updateList(userId, listId, listName);
out.print("列表更新成功。");
} else if ("addTask".equals(action)) { //添加任務(wù)
String listId = request.getParameter("listId");
String taskName = request.getParameter("taskName");
addTask(userId, listId, taskName);
out.print("任務(wù)添加成功。");
} else if ("delTask".equals(action)) { //刪除任務(wù)
String taskId = request.getParameter("taskId");
delTask(userId, taskId);
out.print("任務(wù)刪除成功。");
} else if ("updateTask".equals(action)) { //更新任務(wù)
String taskId = request.getParameter("taskId");
String taskName = request.getParameter("taskName");
updateTask(userId, taskId, taskName);
out.print("任務(wù)更新成功。");
}
%>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -