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

  • 相关阅读:
    IIS 7的 MIME设置自定义下载文件
    jsp用js写时间
    CSS3 必须要知道的10 个顶级命令
    前端必读:浏览器内部工作原理
    文件下载的后台代码
    cookies的简单使用 客户端保存临时数据和上传文件的就Query.uploadify(2.xx版本)的使用
    Myeclipse 如何解决反应慢的问题
    时间插件,validate验证的简单jsp例子
    索引的一些总结
    jQuery选择器中含有空格和没有空格的区别
  • 原文地址:https://www.cnblogs.com/a1111/p/6540306.html
Copyright © 2011-2022 走看看