📄 updatebookservlet.java
字号:
package cn.dang.servlet;
import file_upload.File_upload;
import ghy_db.Conn_Manager;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.dang.entity.Author;
import cn.dang.entity.Book;
import cn.dang.entity.BookType;
import cn.dang.entity.Concem;
import cn.dang.service.AllService;
public class UpdateBookServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public UpdateBookServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
AllService ref = new AllService();
Book book=new Book();
try {
// 创建文件上传对象
File_upload File_upload_ref = new File_upload();
//调用begin_upload()方法获得表单中的元素值并进行图片更新
HashMap hm = File_upload_ref.begin_upload(request, response);
//创建容器对象保存作者名字
ArrayList values_list_author=new ArrayList();
values_list_author.add(hm.get("authorName"));
//创建容器对象保存出版社名字
ArrayList values_list_concem=new ArrayList();
values_list_concem.add(hm.get("bookConcem"));
//更新作者信息
int aid=ref.getAuthorService().getAuthorIdByNameAndUpdate(values_list_concem);
//更新出版社信息
int cid=ref.getConcemService().getConcemIdByNameAndUpdate(values_list_concem);
//创建容器对象保存书籍信息
ArrayList values_list_book=new ArrayList();
values_list_book.add(hm.get("bkName"));
values_list_book.add(cid);
values_list_book.add(hm.get("ISBN"));
values_list_book.add(hm.get("publishTime"));
values_list_book.add(hm.get("price"));
values_list_book.add(hm.get("dangPrice"));
values_list_book.add(hm.get("content"));
values_list_book.add(aid);
values_list_book.add(hm.get("cover"));
values_list_book.add(hm.get("smallType2"));
values_list_book.add(hm.get("bid"));
//跟新书籍
ref.getBookService().updateBookInfo(values_list_book);
//如果所有更新操作成功进行事务提交
Conn_Manager.transaction_commit();
request.setAttribute("message", "更新书籍信息成功");
request.setAttribute("msg", "返回操作书籍信息页面");
request.setAttribute("rightBook", "../manager/rightBook.jsp");
request.getRequestDispatcher("../manager/message.jsp").forward(request, response);
} catch (Throwable e) {
// TODO Auto-generated catch block
Conn_Manager.transaction_rollback();
e.printStackTrace();
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -