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
    	}
    
    }
    

  • 相关阅读:
    AngularJS开发指南6:AngularJS表单详解
    AngularJS开发指南5:AngularJS表达式详解
    AngularJS开发指南4:指令的详解
    grunt入门讲解7:项目脚手架grunt-init
    grunt入门讲解6:grunt使用步骤和总结
    grunt入门讲解5:创建插件,安装Grunt以及常见问题
    grunt入门讲解4:如何创建task(任务)
    grunt入门讲解3:实例讲解使用 Gruntfile 配置任务
    grunt入门讲解2:如何使用 Gruntfile 配置任务
    grunt入门讲解1:grunt的基本概念和使用
  • 原文地址:https://www.cnblogs.com/a1111/p/12816513.html
Copyright © 2011-2022 走看看