求以下每句代码的解释,急

增加书籍到书架 public class AddBookToBookShelf extends HttpServlet { private static final long serialVersionUID = 1L; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); response.setContentType("text/html; charset=UTF-8"); String bs_account = request.getParameter("bs_account"); String _bs_bnum = request.getParameter("bs_bnum"); int bs_bnum = Integer.parseInt(_bs_bnum); String _collectiontimes = request.getParameter("collectiontimes"); String _chapter_num = request.getParameter("chapter_num");//章节编号 //更新收藏数 if(_collectiontimes!=null && !_collectiontimes.equals("")) { BookService bs = new BookServiceImpl(); Book book = new Book(); int collectiontimes = Integer.parseInt(_collectiontimes); book.setCollectiontimes(collectiontimes); book.setBnum(bs_bnum); bs.updateBook(book); } //添加进书架 BookShelfService bss = new BookShelfServiceImpl(); if(!bss.addBookToBookShelf(bs_account, bs_bnum)) { System.out.println("添加失败"); } if(_chapter_num!=null && !_chapter_num.equals("")) { int chapter_num = Integer.parseInt(_chapter_num); //跳转到BookContentServlet response.sendRedirect("BookContentServlet?bc_bnum="+bs_bnum+"&chapter_num="+chapter_num); }else { //跳转到QueryBookServlet response.sendRedirect("QueryBookServlet?bnum="+bs_bnum); } } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } }

你这个代码,没人想去看,请使用代码段粘贴。

代码都是乱的,格式化一下代码.

代码的意思是根据前端传递的参数,来更新书籍的收藏数,以及将收藏的书籍添加到对应用户书架中。


public class AddBookToBookShelf extends HttpServlet { 
	private static final long serialVersionUID = 1L; 
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
		//对客户端提交数据进行中文乱码转换
		request.setCharacterEncoding("utf-8"); 
		//对服务器发送给客户端的数据进行中文乱码处理。
		response.setCharacterEncoding("utf-8"); 
		response.setContentType("text/html; charset=UTF-8"); 
		//获取页面提交的bs_account控件的值
		String bs_account = request.getParameter("bs_account"); 
		//获取页面提交的bs_bnum控件的值
		String _bs_bnum = request.getParameter("bs_bnum"); 
		//转换为int;
		int bs_bnum = Integer.parseInt(_bs_bnum); 
		//获取页面提交的bs_bnum控件的值
		String _collectiontimes = request.getParameter("collectiontimes"); 
		//获取页面提交的chapter_num控件的值
		String _chapter_num = request.getParameter("chapter_num");
		//章节编号 
		//更新收藏数 
		if(_collectiontimes!=null && !_collectiontimes.equals("")) { 
			//创建于后台数据库连接的服务类
			BookService bs = new BookServiceImpl(); 
			Book book = new Book(); 
			//把收藏次数转换为int
			int collectiontimes = Integer.parseInt(_collectiontimes); 
			book.setCollectiontimes(collectiontimes); 
			//修改book的数据
			book.setBnum(bs_bnum); bs.updateBook(book); 
		} 
		//添加进书架 //创建于后台数据库连接的服务类
		BookShelfService bss = new BookShelfServiceImpl(); 
		//新增图书
		if(!bss.addBookToBookShelf(bs_account, bs_bnum)) { 
			System.out.println("添加失败"); 
		} 
		//如果图书没有章节的内容跳转到添加章节的页面
		if(_chapter_num!=null && !_chapter_num.equals("")) { 
			int chapter_num = Integer.parseInt(_chapter_num); 
			//跳转到BookContentServlet 
			response.sendRedirect("BookContentServlet?bc_bnum="+bs_bnum+"&chapter_num="+chapter_num); 
		}else { //如果图书有章节的内容跳转到图书查询页面
			//跳转到QueryBookServlet 
			response.sendRedirect("QueryBookServlet?bnum="+bs_bnum); 
		} 
	} 
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
		//如果前端发送的是post请求,调用doGet方法,意思是:不管前端调用get请求,还是post请求,执行相同的代码doGet方法。
		doGet(request, response); 
	} 
}

 

去采纳,谢谢!

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632