zoukankan      html  css  js  c++  java
  • 新闻发布项目——Servlet类(doCategoryModifyServlet )

    package bdqn.newsManageServlet.Servlet;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import bdqn.newsManageServlet.Dao.categoryTBDao;
    import bdqn.newsManageServlet.Dao.Impl.categoryTBDaoImpl;
    import bdqn.newsManageServlet.entity.categoryTB;
    
    public class doCategoryModifyServlet extends HttpServlet {
    
    	/**
    	 * 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 {
    
    		response.setContentType("text/html;charset=utf-8");
    		PrintWriter out = response.getWriter();
    
    		//获取id
    		request.setCharacterEncoding("utf-8");
    		String name=request.getParameter("categoryName");
    		int id=0;
    		if(request.getParameter("cgid")!=null){
    		 id=Integer.parseInt(request.getParameter("cgid"));
    		}
    		//int id=Integer.parseInt(request.getParameter("cgid"));
    		//调用访问数据称
    		 categoryTBDao cdao=new categoryTBDaoImpl();
    		//1.判断类别是否重复(在数据库中查询)
    		//2.如果有重复,提示错误信息,转发到添加
    		if(cdao.getCateByName(name)!=null){
    			request.setAttribute("ermsg", "类别名已存在!");
    			request.getRequestDispatcher("adminManage/modifyCategory.jsp").forward(request, response);
    			return;
    		}
    		//在数据库中修改
    		categoryTB cate=new categoryTB();
    		cate.setCategoryName(name);
    		cate.setCategoryID(id);
    		int rel=cdao.updateCategory(cate);
    		if(rel>0){
    			//修改成功
    			out.print("<script>alert('修改成功');location.href='adminManage/manageTopic.jsp';</script>");
    
    		}else{
    			request.setAttribute("ermsg", "修改失败");
    			request.getRequestDispatcher("adminManage/modifyCategory.jsp").forward(request, response);
    			return;
    		}
    		
    	}
    
    	/**
    	 * 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 {
    
    		doGet(request, response);
    	}
    
    	/**
    	 * Initialization of the servlet. <br>
    	 *
    	 * @throws ServletException if an error occurs
    	 */
    	public void init() throws ServletException {
    		// Put your code here
    	}
    
    }
    

  • 相关阅读:
    'live-server' 不是内部或外部命令,也不是可运行的程序 或批处理文件。(解决)
    Node.js安装及环境配置之Windows篇
    开发模式
    IOS13越狱后虚拟定位插件的推荐,relocate
    python,向列表中追加字典,被最后的值覆盖的问题解决办法
    博客园cnblog使用百度统计等站长统计的方法
    IOS解锁哔哩哔哩大会员免费版越狱插件的cydia源
    filza无法安装deb(filza command not found)的解决办法
    Mac 中dock栏图标中文乱码英文正常的解决办法
    关于NVIDIA显卡控制面板中“调整桌面颜色设置”在重启后设置失效的处理方法
  • 原文地址:https://www.cnblogs.com/a1111/p/12816513.html
Copyright © 2011-2022 走看看