接下来是Action里面的代码,暂时定义这个Action 是ComputerAction,代码如下:
package com.action;
import org.apache.struts.action.Action; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionForm; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession;
import com.form.LoginForm; import com.util.LoginBean; import com.util.ComputerBean; import com.util.BaseView; import com.util.Page; import com.model.FunctionManager; import com.attribute.Constants; import com.attribute.SQLBook;
import java.sql.ResultSet;
/** * Created by IntelliJ IDEA. * User: 7612CE * Date: 2005-6-14 * Time: 13:31:34 * To change this template use Options | File Templates. */ public class ComputerAction extends BaseAction { private Log log=LogFactory.getLog(this.getClass().getName());
public ActionForward execute(ActionMapping mapping, ActionForm Form, HttpServletRequest request, HttpServletResponse response){ boolean flag=false; Object[][] obj=null; Page page=new Page(); Integer id=new Integer(Constants.id); String sql=SQLBook.Computer_select_SQL; BaseView view=new BaseView(); String pageNo = request.getParameter("pageNo"); if (pageNo == null || pageNo.equals("null") || pageNo.length() <= 0) { pageNo = "1"; } try{ Object[] table={id}; ComputerBean computerBean=new ComputerBean(); computerBean.setBeanDate(sql,table); computerBean.setPageNo(pageNo); page=computerBean.getResult(); obj=page.getData(); if(!obj.equals(null)){ flag=true; view.setObject(obj); request.setAttribute(Constants.QUERY_RESULT,view); request.setAttribute("page",page); }
}catch(Exception ex){ ex.printStackTrace(); } log.info("system print the flag ="+flag); if(flag){ return(mapping.findForward(Constants.FORWARD_SUCCESS)); }else{ return(mapping.findForward(Constants.FORWARD_FAILURE)); } } }
|