?? gyousyasearchaction.java
字號:
//Created by MyEclipse Struts
// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.0.1/xslt/JavaClass.xsl
package com.dut.struts.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.dut.dao.BatchDBConnectionUtil;
import com.dut.logic.db.Gyousya;
import java.sql.ResultSet;
import java.util.ArrayList;
/**
* MyEclipse Struts
* Creation date: 04-12-2006
*
* XDoclet definition:
* @struts.action path="/gyousyaSearch" name="gyousyaUpdateActionForm" input="/pages/GyousyaInput.jsp" scope="request" validate="true"
* @struts.action-forward name="ok" path="/pages/GyousyaSearch.jsp"
*/
public class GyousyaSearchAction extends Action {
// --------------------------------------------------------- Instance Variables
// --------------------------------------------------------- Methods
/**
* Method execute
* 對"契約業者情報検索結果一覧"頁的"前ページへ"鏈接和"後ページへ "鏈接進行方法調用,數據處理和轉頁
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @author 趙倩 04-12-2006
*/
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
//GyousyaUpdateActionForm gyousyaUpdateActionForm = (GyousyaUpdateActionForm) form;
// TODO Auto-generated method stub
ActionForward forward=null;
String mess=null;
mess=request.getParameter("mess");
Gyousya aa=new Gyousya();
int numall=0;
/**當無檢索條件進行查詢檢索時,得到的要檢索的數據總數*/
numall=aa.NumAll();
int yeshu=0;
/**當無檢索條件進行查詢檢索時,得到所查詢的數據總數按照10條一頁分,分成幾個頁*/
if(numall%10==0){
/**當總數據數的個位為0,或者總數據數為小于等于十時的分頁數*/
yeshu=numall/10;
}
else{
/**當總數據數的個位不為0,總數據數大于十時的分頁數*/
yeshu=(numall/10)+1;
}
int gewei=0;
/**當無檢索條件進行查詢檢索時,得到查詢出的總數據數的個位數*/
gewei=(numall%10);
ArrayList list=new ArrayList();
int from=0;
ResultSet rs=null;
String qiID=null;
String qiName=null;
/**在進入此action時先把壓在session中的"list"移除,以免在這個action中壓"list"時混淆*/
request.getSession().removeAttribute("list");
qiID=(String)request.getSession().getAttribute("qiID");
qiName=(String)request.getSession().getAttribute("qiName");
//***************************************************************************************************
/**以契約業者ID查詢時的數據顯示,但不分頁,因為按此條件查只能查一條信息*/
if(qiID==null){
}
else{
rs=aa.Jiansuo(qiID,0);
/** 把"契約業者情報検索結果一覧"中的第一條信息對應在結果集中的位置壓在request里*/
request.setAttribute("where","1");
/** 把"契約業者情報検索結果一覧"中的最后一條信息對應在結果集中的位置壓在request里*/
request.setAttribute("to","1");
}
//********************************************************************************************************
/**以契約業者NAEM查詢時的數據查詢,顯示,分頁*/
if(qiName==null){
}
else{
rs=aa.Jiansuo(qiName,1);
numall=aa.getRows(rs);
/**以契約業者NAEM查詢時,得到所查詢的數據總數按照10條一頁分,分成幾個頁*/
if(numall%10==0){
/**當總數據數的個位為0,或者總數據數為小于等于十時的分頁數*/
yeshu=numall/10;
}
else{
/**當總數據數的個位不為0,總數據數大于十時的分頁數*/
yeshu=(numall/10)+1;
}
/**以契約業者NAEM查詢時,得到查詢出的總數據數的個位數*/
gewei=(numall%10);
if(numall<=10){
rs=aa.selectMess(qiName,1,0,numall);
request.setAttribute("where",Integer.toString(1));
request.setAttribute("to",Integer.toString(numall));
request.getSession().setAttribute("from","1");
}
/**以契約業者NAEM查詢時,查詢的數據總數大于10時*/
else{
/**得到當前所在頁*/
from=Integer.parseInt((String)request.getSession().getAttribute("from"));
/**當按下"契約業者情報検索結果一覧"的"前ページへ"鏈接時數據查詢,顯示,分頁等*/
if(mess.equals("qian")){
/**當當前頁為第一頁或第二頁,點擊按鈕后上一頁顯示的是總數據的前10條數據*/
if(from==1||from==2){
/**轉向"GyousyaSearchDispatchAction,指向分頁中的第一頁"*/
ActionForward forward1=mapping.findForward("first");
forward=forward1;
}
/**當當前頁不是分頁中的第一頁或第二頁,點擊按鈕后上一頁顯示的是此頁第一個數據之前的10條數據*/
else{
/**以契約業者NAEM查詢,得到此頁第一個數據之前的10條數據*/
rs=aa.selectMess(qiName,1,(from-2)*10,10);
/** 把下一頁顯示的第一條信息對應在結果集中的位置壓在request里*/
request.setAttribute("where",Integer.toString((from-2)*10+1));
/** 把下一頁顯示的最后一條信息對應在結果集中的位置壓在request里*/
request.setAttribute("to",Integer.toString((from-2)*10+10));
String str_from=Integer.toString(from-1);
/**把下一頁在分頁中對應的第幾頁存在session中*/
request.getSession().setAttribute("from",str_from);
}
}
/**當按下"契約業者情報検索結果一覧"的"後ページへ "鏈接時數據查詢,顯示,分頁等*/
else if(mess.equals("hou")){
/**當當前頁為倒數第一頁或第二頁,點擊按鈕后下一頁顯示的是總數據的最后"gewei"條數據*/
if(from==yeshu||from==(yeshu-1)){
/**當以契約業者NAEM查詢時,查出的總數據個位數為0時*/
if(gewei==0){
/**因為,查出的總數據個位數為0,所以最后一頁查詢顯示的也是10條數據*/
rs=aa.selectMess(qiName,1,(numall-10),10);
/** 把下一頁顯示的第一條信息對應在結果集中的位置壓在request里*/
request.setAttribute("where",Integer.toString((numall-10)+1));
/** 把下一頁顯示的最后一條信息對應在結果集中的位置壓在request里*/
request.setAttribute("to",Integer.toString((numall-10)+10));
}
/**當以契約業者NAEM查詢時,查出的總數據個位數不為0時*/
else{
/**最后一頁查詢顯示的是總數據的最后"gewei"條數據*/
rs=aa.selectMess(qiName,1,(numall-gewei),gewei);
/** 把下一頁顯示的第一條信息對應在結果集中的位置壓在request里*/
request.setAttribute("where",Integer.toString((numall-gewei)+1));
/** 把下一頁顯示的最后一條信息對應在結果集中的位置壓在request里*/
request.setAttribute("to",Integer.toString((numall-gewei)+gewei));
}
/**把下一頁在分頁中對應的頁數壓進session中*/
if(from==yeshu){
String str_from=Integer.toString(from);
request.getSession().setAttribute("from",str_from);
}
else{
String str_from=Integer.toString(from+1);
request.getSession().setAttribute("from",str_from);
}
}
/**當當前頁在分頁中除倒數第一頁或倒數第二頁時*/
else{
/**以契約業者NAEM查詢,得到此頁最后一個數據之后的10條數據*/
rs=aa.selectMess(qiName,1,from*10,10);
/** 把下一頁顯示的第一條信息對應在結果集中的位置壓在request里*/
request.setAttribute("where",Integer.toString((from*10)+1));
/** 把下一頁顯示的最后一條信息對應在結果集中的位置壓在request里*/
request.setAttribute("to",Integer.toString((from*10)+10));
/**把下一頁在分頁中對應的頁數壓進session中*/
String str_from=Integer.toString(from+1);
request.getSession().setAttribute("from",str_from);
}
}else{
rs=aa.selectMess(qiName,1,0,10);
request.setAttribute("where",Integer.toString(1));
request.setAttribute("to",Integer.toString(10));
request.getSession().setAttribute("from","1");
}
}
}
//********************************************************************************************************
/**當無檢索條件進行檢索時,對數據的查詢,顯示,分頁,跟上面的"以契約業者NAEM查詢時對數據的查詢,顯示,分頁"步驟大致相同,這里不做過多解釋,看會"以契約業者NAEM查詢時對數據的查詢,顯示,分頁"就能看會這個*/
if(qiID==null&&qiName==null){
if(numall<=10){
rs=aa.selectMess(null,2,0,numall);
request.setAttribute("where",Integer.toString(1));
request.setAttribute("to",Integer.toString(numall));
}
else{
from=Integer.parseInt((String)request.getSession().getAttribute("from"));
request.getSession().removeAttribute("from");
request.getSession().removeAttribute("qiID");
request.getSession().removeAttribute("qiName");
if(mess==null||mess.equals("")){
rs=aa.selectMess(null,2,0,10);
request.setAttribute("where",Integer.toString(1));
request.setAttribute("to",Integer.toString(10));
request.getSession().setAttribute("from","1");
}else if(mess.equals("qian")){
if(from==1||from==2){
ActionForward forward1=mapping.findForward("first");
forward=forward1;
}
else{
rs=aa.selectMess(null,2,(from-2)*10,10);
request.setAttribute("where",Integer.toString((from-2)*10+1));
request.setAttribute("to",Integer.toString((from-2)*10+10));
String str_from=Integer.toString(from-1);
request.getSession().setAttribute("from",str_from);
}
}else if(mess.equals("hou")){
if(from==yeshu||from==(yeshu-1)){
if(gewei==0){
rs=aa.selectMess(null,2,(numall-10),10);
request.setAttribute("where",Integer.toString((numall-10)+1));
request.setAttribute("to",Integer.toString((numall-10)+10));
}
else{
rs=aa.selectMess(null,2,(numall-gewei),gewei);
request.setAttribute("where",Integer.toString((numall-gewei)+1));
request.setAttribute("to",Integer.toString((numall-gewei)+gewei));
}
if(from==yeshu){
String str_from=Integer.toString(from);
request.getSession().setAttribute("from",str_from);
}
else{
String str_from=Integer.toString(from+1);
request.getSession().setAttribute("from",str_from);
}
}
else{
rs=aa.selectMess(null,2,from*10,10);
request.setAttribute("where",Integer.toString(from*10+1));
request.setAttribute("to",Integer.toString((from*10)+10));
String str_from=Integer.toString(from+1);
request.getSession().setAttribute("from",str_from);
}
}
}
}
/**把最終查詢出的結果集處理成ArrayList,壓入session,在JSP頁面進行循環輸出*/
if(rs==null){
}
else{
/**把最終查詢出的結果集處理成ArrayList*/
list=aa.Messlist(rs);
/**把ArrayList壓入session,為在JSP頁面進行循環輸出*/
request.getSession().setAttribute("list",list);
/**轉頁,轉向"契約業者情報検索結果一覧"頁*/
ActionForward forward2=mapping.findForward("next");
forward=forward2;
}
return forward;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -