CSDN博客

img flyying

Pagelet

发表于2004/10/18 11:25:00  675人阅读

package jsswt.sendsms;
/**
 *
 * <p>Title: 求购,供求,合作信息的显示</p>
 * <p>Description:
 * 引入页点击Swt/Swcenter.jsp执行StockServlet,ProvideServlet,CooperateServlet</p>
 * 功能:带分页显示求购,供求,合作信息.在供求商机中执行求购,供求,合作三个专区的
 *      stockservlet(provideservlet,cooperateservlet),获得sql语句.servletname名
 *      datasource名.返回页的url地址.
 *      返回Swt/Index_info.jsp.
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: LNGl</p>
 * @author : flyying
 * @version 1.0
 */

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import jsswt.sendsms.DBO;

public class Pagelet extends HttpServlet
{
        public long currentPage=1;//当前页
        private String selPage="1"; //select 选择页
        public String sql=""; //用于获得查询结果的sql语句
        public String sql1=null;//用于取得总数的sql语句
        public Vector pageData = new Vector(); //pageData用于存储jsp页面显示的内容
        public HttpSession session = null;  //pagedata存在session里面然后在showdata.jsp中读取
        public HttpServletRequest request = null; //声明request变量
        public HttpServletResponse response=null; //声明response变量
        public DBO dbo = null; //声明dbo用来与模式层通信
        public String dataSource="dataSource";
        public int totalRec;//总记录条数
        public long totalPage; //总页数
        public int pageSize=12;//设定每一页显示数据的条数
        public String servletName;//servletname名
        public String css;//暂时无用
        public int toPage;
        public String aaa;
        public String url1;
        public String type;//参数:区别是哪个信息.(求购,供求,合作)
        public String selProvince="0000";
        //init方法 声明servlet
        public void init() throws ServletException{
          System.out.println("123423653456746574785678");
        }
        public void showData(){
          //一页显示数据save到session中
          session.setAttribute("selProvince",selProvince);
          session.setAttribute("pageData",pageData) ;

          request.setAttribute("servletname",servletName);
          request.setAttribute("totalrec",String.valueOf(totalRec));
          request.setAttribute("currentpage",String.valueOf(currentPage));

          try {
            //调用showdata.jsp显示
            RequestDispatcher requestDispatcher=request.getRequestDispatcher(url1);
            requestDispatcher.forward(request,response);
          }
          catch (Exception ex) {
            ex.printStackTrace();
          }
        }
        public final void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{
          try {
            response.setContentType("text/html; charset=GBK");
            this.request = request;
            this.response = response;
            this.session = request.getSession();
            String ssss=request.getParameter ("page");
            type=request.getParameter("type");
            request.setAttribute("type",type);//保存.页面调用.
            if(sql!=null || sql!=""){

            }else{
              String aaa=request.getParameter("sql");
              sql=aaa;
            }

            int aa = 0;
            if (ssss!=null){
               aa=Integer.parseInt(ssss);
            }
            selPage=request.getParameter("selPage");
            if (selPage != null){
              currentPage=Integer.parseInt(selPage);
            }

            if (aa == -1){
              currentPage = 1;
            }
            else{
              if (aa == -2){
                currentPage=currentPage-1;
              }
              else{
                if(aa == -3){
                  currentPage=currentPage+1;
                }
              }
            }
//            currentPage = Integer.parseInt(ssss);
            //实例dbo对象
            dbo = new DBO(this, dataSource);
            if (sql1!=null){
              totalRec=dbo.queryTotalRec(sql1);
            }
            else{
              totalRec=dbo.queryTotal(sql);
            }
            pageData = dbo.queryPage(totalRec,sql,currentPage,pageSize);

            if (totalRec==0){
              totalRec=dbo.getTotalRec();
            }
            showData();
          }
          catch (Exception ex) {
            ex.toString();
          }
        }
        public final void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{
               doGet(request,response);
        }
}

阅读全文
0 0

相关文章推荐

img
取 消
img