www.pudn.com > MyPageTest.rar > LoginAction.java


/* 
 * Generated by MyEclipse Struts 
 * Template path: templates/java/JavaClass.vtl 
 */ 
package strut.action; 
 
import java.util.List; 
 
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.apache.struts.actions.DispatchAction; 
 
import com.bo.UserBO; 
 
import strut.form.LoginForm; 
 
/**  
 * MyEclipse Struts 
 * Creation date: 04-05-2008 
 *  
 * XDoclet definition: 
 * @struts.action path="/login" name="loginForm" parameter="action" scope="request" validate="true" 
 */ 
public class LoginAction extends DispatchAction { 
	/* 
	 * Generated Methods 
	 */ 
 
	/**  
	 * Method execute 
	 * @param mapping 
	 * @param form 
	 * @param request 
	 * @param response 
	 * @return ActionForward 
	 */ 
	public ActionForward page(ActionMapping mapping, ActionForm form, 
			HttpServletRequest request, HttpServletResponse response) { 
		LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub 
		List lt=null; 
		int page=0;//初始页面数 
		int count=0;//初始记录数 
		int now_page=1;//初始当前页 
		int temp_now_page=0;//临时变量保存当前页 
		UserBO bo=new UserBO(); 
		ActionErrors errors=new ActionErrors(); 
		String go=request.getParameter("go");//获取要跳转的页面 
		String next=request.getParameter("next");//下一次要显示的页面 
		count=bo.count();//获取记录 
		if(count==0){//无记录时候 
        errors.add("no",new ActionError("page.isnull")); 
        saveErrors(request,errors); 
//    	return mapping.getInputForward(); 
		} 
		if(count%2==0){ 
			page=count/2; 
		}else{ 
			page=count/2+1; 
		} 
		if(go!=null){//判断是否用户要跳转 
			try { 
				now_page = Integer.parseInt(go);//当接受的不是数字时候 
			} catch (Exception e) { 
				// TODO: handle exception 
				errors.add("no",new ActionError("errors.numformat")); 
				saveErrors(request,errors); 
				return mapping.findForward("page"); 
			}			 
		}else 
			if(next!=null){ 
				 
			try { 
				now_page = Integer.parseInt(next);//当接受不是数字时候 
			} catch (Exception e) { 
				// TODO: handle exception 
				errors.add("no",new ActionError("errors.numformat")); 
				saveErrors(request,errors); 
				return mapping.findForward("page"); 
			}			 
		}else{ 
			now_page=1; 
		} 
		if(now_page>page){//当用户输入过大时候 
			errors.add("no",new ActionError("errors.toolong",page,page)); 
		saveErrors(request,errors); 
		return mapping.getInputForward(); 
			 
		} 
	    temp_now_page=now_page-1; 
		lt=bo.page(temp_now_page); 
		String page_cut=bo.page_cut(page, now_page); 
	 
		request.setAttribute("page_cut",page_cut); 
		 
		request.setAttribute("lt",lt); 
 
		return mapping.findForward("page"); 
	} 
}