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

  • 相关阅读:
    POJ 3458 Colour Sequence(简单题)
    Cygwin下vim按方向键出现ABCD;
    算法之旅——归并排序
    poj 2769 Reduced ID Numbers(memset使用技巧)
    Restlet+Fastjson 高速构建轻量级 Java RESTful Webservice
    poj 1659 Frogs&#39; Neighborhood (度序列)
    PHP监測memcache服务端的执行状况
    机器学习之倚门回首嗅青梅
    Threejs 官网
    sqlserver安全加固
  • 原文地址:https://www.cnblogs.com/a1111/p/12816513.html
Copyright © 2011-2022 走看看