⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modifybookmanageraction.java

📁 这是本人曾经在公司里用的,内部开发框架,基于struts+hibernate今天分享给大家
💻 JAVA
字号:
/**
 * 
 */
package test.book;

import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.Session;

import cn.bway.common.BwayHibernateException;
import cn.bway.common.WebConstant;
import cn.bway.common.action.BaseAction;
import cn.bway.common.dao.HibernateSessionFactory;

/**
 * @author Kson
 *
 */
public class ModifyBookmanagerAction extends BaseAction {

	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws UnsupportedEncodingException 
	 * @throws Exception
	 */
	
	public ActionForward execute(ActionMapping mapping,
				ActionForm form,HttpServletRequest request,	HttpServletResponse response)
				throws BwayHibernateException, UnsupportedEncodingException {
		
		ActionErrors errors = new ActionErrors();
		String returnStr = WebConstant.FORWARD_SUCCESS;
		Session sess=null;
		Connection conn=null;
		
		//request.setCharacterEncoding("gb2312");
		String id = request.getParameter("id");
		String Modifymenufatherid = request.getParameter("Modifymenufatherid");
		String Modifymenuid = request.getParameter("Modifymenuid");
		String treename = request.getParameter("treename2");
		
		System.out.println("the treename:  "+treename);
		
		try {
			sess=HibernateSessionFactory.currentSession();
			conn=sess.connection();
			conn.setAutoCommit(false);
			
			String sql = "update bookmanager set menuid ='"+Modifymenuid+"' " +
					", munefatherid ='"+Modifymenufatherid+"' , menuname ='"+treename+"'" +
							" where id = '"+id+"'  ";
			log.info(" the update bookmanger type sql:   "+sql);
			conn.createStatement().executeUpdate(sql);
			returnStr=WebConstant.FORWARD_SUCCESS;
			request.setAttribute(WebConstant.RETURN_Message,"修改成功!");
			
			conn.commit();
		} catch (Exception e) {
			returnStr=WebConstant.FORWARD_FAIL;
			errors.add(ActionErrors.GLOBAL_ERROR,new ActionError("edu.system.excption",e.getMessage()));
			this.saveErrors(request,errors);
			try {
				conn.rollback();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			e.printStackTrace();
		}finally{
			if(null !=conn){
				try {
					conn.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			HibernateSessionFactory.closeSession();
    	}
		return mapping.findForward(returnStr);
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -