<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    jimphei學習工作室

    jimphei學習工作室

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      23 隨筆 :: 0 文章 :: 1 評論 :: 0 Trackbacks

    (一)、經常用的過濾器

     1package com.ascent.util;
     2
     3import java.io.IOException;
     4import javax.servlet.Filter;
     5import javax.servlet.FilterChain;
     6import javax.servlet.FilterConfig;
     7import javax.servlet.ServletException;
     8import javax.servlet.ServletRequest;
     9import javax.servlet.ServletResponse;
    10import javax.servlet.UnavailableException;
    11
    12/**
    13 * Example filter that sets the character encoding to be used in parsing the
    14 * incoming request
    15 */

    16public class SetCharacterEncodingFilter implements Filter {
    17
    18    /**
    19     * Take this filter out of service.
    20     */

    21    public void destroy() {
    22    }

    23    /**
    24     * Select and set (if specified) the character encoding to be used to
    25     * interpret request parameters for this request.
    26     */

    27    public void doFilter(ServletRequest request, ServletResponse response,
    28    FilterChain chain)throws IOException, ServletException {
    29
    30    request.setCharacterEncoding("gb2312");
    31
    32    // 傳遞控制到下一個過濾器
    33    chain.doFilter(request, response);
    34    }

    35
    36    public void init(FilterConfig filterConfig) throws ServletException {
    37    }

    38}

    39

    (二)、購物車類代碼
    package com.ascent.util;

    import java.util.HashMap;

    import com.ascent.po.Product;

    public class ShopCart {
        
    private HashMap<String, Product> hashMap;
        
        
    public HashMap<String, Product> getHashMap() {
            
    return hashMap;
        }


        
    public void setHashMap(HashMap<String, Product> hashMap) {
            
    this.hashMap = hashMap;
        }


        @SuppressWarnings(
    "unchecked")
        
    public ShopCart(){
            hashMap 
    = new HashMap();
        }

        
        
    /**
         * 檢查hashmap中是否有了該pid對應的對象方法
         * 
    @param pid
         * 
    @return true:有   false:無
         
    */

        
    public boolean checkPid(String pid){
            
    if(hashMap.containsKey(pid)){
                
    return true;
            }
    else{
                
    return false;
            }

        }

        
    /**
         * 在上面方法返回false情況下添加product
         * 
    @param pid
         * 
    @param product
         
    */

        
    public void addProduct(String pid,Product product){
            hashMap.put(pid, product);
        }

        
        
    /**
         * 根據id刪除hashmap中的product
         * 
    @param pid
         
    */

        
    public void delProduct(String pid){
            hashMap.remove(pid);
        }

        
        
    /**
         * 修改hashmap中pid對應product的質量quantity
         * 
    @param pid
         * 
    @param quantity
         
    */

        
    public void updateQuantity(String pid,String quantity){
            hashMap.get(pid).setQuantity(quantity);
        }

        
        
    /**
         * 清除購物車
         
    */

        
    public void emptyCart(){
            
    this.getHashMap().clear();
        }

    }


    (三)、分頁算法
    //分頁類
    package com.ascent.util;
    import java.util.*;
    /**
     * 
    @author Administrator
     * 
    @version 負責頁面控制的 JavaBean
     
    */

    public class PageBean {            
        
    public int currentPage;                // 當前頁數
        public int totalPage;                // 總頁數
        public int totalRows;                // 總行數
        public int rowsPage = 5;            // 每頁顯示多少行
        public ArrayList data;                // 封裝頁面顯示的數據
        public PageBean(){}
        
    public void countTotalPage(){        // 計算總頁數
            if(totalRows%rowsPage==0){
                
    this.totalPage = totalRows/rowsPage;
            }

            
    else{
                
    this.totalPage = totalRows/rowsPage + 1;
            }

        }

        
    public ArrayList getData(){                
            
    return data;
        }

        
        
    public PageBean(int totalRows){
            
    this.totalRows = totalRows;
            
    this.countTotalPage();
        }

    }





        
    // 分頁算法
        public String guestPageShow() throws Exception {
            
    this.pageReturn();
            
    return "guestproductsshow";
        }


        @SuppressWarnings(
    "unchecked")
        
    private void pageReturn() {
            String jump_page 
    = this.getJumpPage();
            
    if (jump_page == null{
                jump_page 
    = "1";
            }

            PageBean page 
    = this.listData(jump_page);
            ActionContext.getContext().getSession().put(
    "product_page_list", page);
            
    this.setDataList(page.getData());
        }


        
    public PageBean listData(String number) {
            PageBean page 
    = new PageBean(productService.getTotalRows());
            
    int num = Integer.parseInt(number);
            String sql 
    = "from Product p where delFlag=0 order by p.pid";
            page.data 
    = productService.getData(sql, page.rowsPage * (num - 1),
                    page.rowsPage);
            page.currentPage 
    = num;
            
    return page;

        }


        
    // 分頁算法


    //實現
                    PageBean page=this.listData("1");
                    ActionContext.getContext().getSession().put(
    "productuser_page_list", page);
                    
                    
    this.setDataList(page.getData());



    //jsp方面

      
    <%
     PageBean pBean 
    = (PageBean)session.getAttribute("productuser_page_list");
     
    %>
     
    <%
     
    if(pBean.totalPage!=1){  
     
    %>   
           
    <form name="pageForm" action="pageProductuserManagerAction.action" method="post">         
          
    <%@ include file="page.jsp" %>   
          
    </form>         
          
    <%}
     %>    

    //page.jsp

    <%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>

      
    <script language="JavaScript">
        function Jumping()
    {
           document.pageForm.submit();         
        }
        
        function gotoPage(pagenum)
    {
            
    //alert(pagenum);
            
    //alert(document.pageForm.jumpPage.value);
           document.pageForm.jumpPage.value = pagenum;
           document.pageForm.submit();       
        }

      
    </script>    
            
    <table>  
              
    <tr>
                
    <td>每頁<%=pBean.rowsPage%></td>
                
    <td><%=pBean.totalRows%></td>
                
    <td><%=pBean.currentPage%></td><td><%=pBean.totalPage%></td>
                
    <td>
                    
    <%if(pBean.currentPage==1){out.print("首頁 上一頁");}else{%>
                  
    <a href="javascript:gotoPage(1)">首頁</a>
                  
    <a href="javascript:gotoPage(<%=pBean.currentPage-1%>)">上一頁</a>
                  
    <%
                  }

                   
    %> 
                   
    <%if(pBean.currentPage==pBean.totalPage){out.print("下一頁 尾頁");}else{%>
                   
    <a href="javascript:gotoPage(<%=pBean.currentPage+1%>)">下一頁</a>
                   
    <a href="javascript:gotoPage(<%=pBean.totalPage%>)">尾頁</a>
                   
    <%}
     %>
                
    </td>
                
    <td>                
                         轉到第
    <select name="jumpPage" onchange="Jumping()">
                          
    <%for(int i=1;i<=pBean.totalPage;i++){
                              
    if(i==pBean.currentPage){
                          
    %>
                          
                          
    <option selected value=<%=i%>><%=i%></option>
                          
    <%
                          }

                          
    else
                          
    {
                           
    %>
                           
    <option value=<%=i%>><%=i%></option>
                           
    <%
                           }

                           }

                            
    %>
                            
    </select>
                  
    </td>
              
    </tr>
            
    </table>
          
            


    這個ssh項目的配置文件
    posted on 2009-03-13 17:16 jimphei 閱讀(230) 評論(1)  編輯  收藏

    評論

    # re: 電子商務系統的一些代碼[未登錄] 2009-03-18 18:28 sclsch
    頁面上邏輯不能封裝到bean里頭?  回復  更多評論
      


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 亚洲欧美成人av在线观看| 一个人看的www在线免费视频| 日韩免费观看的一级毛片| 日韩在线视频免费| 亚洲成人在线网站| 日韩免费观看的一级毛片| 免费日本一区二区| 亚洲女子高潮不断爆白浆| 亚洲色精品vr一区二区三区| 黄色永久免费网站| 一级毛片不卡免费看老司机| 亚洲一区二区免费视频| 精品亚洲视频在线观看| 亚洲人成网站免费播放| 国产精品免费久久久久影院 | 亚洲人成影院在线无码观看| 67194国产精品免费观看| 在线亚洲v日韩v| 亚洲最新在线视频| 中文字幕人成人乱码亚洲电影| 中字幕视频在线永久在线观看免费| 五月天婷婷精品免费视频| 亚洲中文久久精品无码1| 国产亚洲精品资源在线26u| 免费的一级片网站| 最近中文字幕免费2019| 国产精品成人免费观看| 九九精品国产亚洲AV日韩| 亚洲欧洲校园自拍都市| 亚洲欧洲成人精品香蕉网| 国产青草视频免费观看97 | 男人进去女人爽免费视频国产| 亚洲av成人一区二区三区观看在线| 亚洲综合一区二区精品导航| 亚洲精品人成无码中文毛片| 女人与禽交视频免费看| 中文字幕视频免费| 免费网站观看WWW在线观看| 免费人成动漫在线播放r18| 亚洲人成网站色7799| 亚洲国产成人精品无码区在线秒播|