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

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

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

    gdufo

     

    實戰Struts-Menu(4)

    /**
         * 從數據庫中讀取菜單配置信息
         * 
         * 
    @return
         
    */
        
    private Map[] getMenuComponents() {
            ArrayList list 
    = new ArrayList();
            Connection conn 
    = null;
            PreparedStatement pstmt 
    = null;
            ResultSet rest 
    = null;
            String sql 
    = "select name,parent_name,title,location,description from menu_item order by id";
            
    try {
                Class.forName(
    "com.mysql.jdbc.Driver").newInstance();
                conn 
    = DriverManager.getConnection("jdbc:mysql://localhost/myexamples?user=root&password=mywangya&useUnicode=true&characterEncoding=UTF-8");
                pstmt 
    = conn.prepareStatement(sql);
                rest 
    = pstmt.executeQuery();
                
    while (rest.next()) {
                    
    int i = 1;
                    HashMap map 
    = new HashMap();
                    map.put(
    "name", rest.getString(i++));
                    map.put(
    "parent_name", rest.getString(i++));
                    map.put(
    "title", rest.getString(i++));
                    map.put(
    "location", rest.getString(i++));
                    map.put(
    "description", rest.getString(i++));
                    list.add(map);
                }
            } 
    catch (SQLException ex) {
                ex.printStackTrace();
            } 
    catch (InstantiationException e) {
                e.printStackTrace();
            } 
    catch (IllegalAccessException e) {
                e.printStackTrace();
            } 
    catch (ClassNotFoundException e) {
                e.printStackTrace();
            } 
    finally {
                
    try {
                    
    if (null!=rest) rest.close();
                    
    if (null!=pstmt) pstmt.close();
                    
    if (null!=conn) conn.close();
                } 
    catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            
            
    return (Map[]) list.toArray(new HashMap[0]);
        }
        
        
    /**
         * 構造菜單權限
         * 
         * 
    @param request
         
    */
        
    private void buildMenuPermissions(HttpServletRequest request) {
            PermissionsAdapter permession 
    = new PermissionsAdapter() {
                
    public boolean isAllowed(MenuComponent menu) {
                    
    // 名稱等于StandaloneMenu的菜單不顯示
                    return !"StandaloneMenu".equalsIgnoreCase(menu.getName());
                }
            };
            request.setAttribute(
    "examplesPermession", permession);
        }

        
    /**
         * 構造菜單顯示標題
         * 
         * 
    @param request
         
    */
        
    private void buildMenuResourceBundle(HttpServletRequest request) {
            MenuResourceBundle resourceBundle 
    = new MenuResourceBundle();
            request.setAttribute(
    "examplesBundle", resourceBundle);
        }
        
        
    /**
         * MenuResourceBundle樹狀菜單國際語言顯示
         * 
         * 
    @author wenbin.zhang
         *  
         
    */
        
    class MenuResourceBundle extends ListResourceBundle {
            
    private ArrayList list = new ArrayList();

            
    public MenuResourceBundle() {
                Connection conn 
    = null;
                PreparedStatement pstmt 
    = null;
                ResultSet rest 
    = null;
                String sql 
    = "select title,titleCN from menu_item order by id";
                
    try {
                    Class.forName(
    "com.mysql.jdbc.Driver").newInstance();
                    conn 
    = DriverManager.getConnection("jdbc:mysql://localhost/myexamples?user=root&password=mywangya&useUnicode=true&characterEncoding=UTF-8");
                    pstmt 
    = conn.prepareStatement(sql);
                    rest 
    = pstmt.executeQuery();
                    
    while (rest.next()) {
                        
    int i = 1;
                        String[] message 
    = new String[2];
                        message[
    0= rest.getString(i++);
                        
    try {
                            message[
    1= new String(rest.getString(i++).getBytes("latin1"), "gbk");
                        } 
    catch (UnsupportedEncodingException e) {
                            e.printStackTrace();
                        }
                        
    if (message[0!= null && message[1!= null) {
                            list.add(message);
                        }
                    }
                } 
    catch (SQLException ex) {
                    ex.printStackTrace();
                } 
    catch (InstantiationException e) {
                    e.printStackTrace();
                } 
    catch (IllegalAccessException e) {
                    e.printStackTrace();
                } 
    catch (ClassNotFoundException e) {
                    e.printStackTrace();
                } 
    finally {
                    
    try {
                        
    if (null!=rest) rest.close();
                        
    if (null!=pstmt) pstmt.close();
                        
    if (null!=conn) conn.close();
                    } 
    catch (SQLException e) {
                        e.printStackTrace();
                    }
                }

            }

            
    public Object[][] getContents() {
                
    return (String[][]) list.toArray(new String[0][0]);
            }
        }
    }

    > 將struts-config.xml文件的<action-mappings />部分修改為:
    <action-mappings>
      
    <action path="/menuAction" type="cn.appex.menu.MenuAction" >
        
    <forward name="success" path="/struts-menu/dynamic-menu.jsp" />
      
    </action>
    </action-mappings>

    posted on 2008-08-05 15:05 gdufo 閱讀(262) 評論(0)  編輯  收藏 所屬分類: Struts2

    導航

    統計

    常用鏈接

    留言簿(6)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    收藏夾

    Hibernate

    友情鏈接

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲国产精品特色大片观看完整版 | 亚洲AV无码一区二区乱孑伦AS| 亚洲国产成人高清在线观看 | 中文字幕在线免费| 成人免费视频69| 在线观看亚洲免费| 亚洲欧洲∨国产一区二区三区| 亚洲AV无码成人精品区在线观看 | 亚洲一区二区三区在线网站| 免费毛片毛片网址| 在线观看免费人成视频色9| 亚洲中文字幕无码专区| 亚洲国产亚洲综合在线尤物| 男女猛烈无遮掩视频免费软件 | 黄色一级免费网站| 日本片免费观看一区二区| 在线a亚洲v天堂网2019无码| 亚洲精品无码av片| 91精品国产免费久久久久久青草| 亚洲欧洲日韩国产| 久久免费高清视频| 丝袜熟女国偷自产中文字幕亚洲| 一个人免费视频在线观看www | 国外成人免费高清激情视频| 亚洲一区二区三区香蕉| 国产成人一区二区三区视频免费| 亚洲精品国自产拍在线观看| 亚洲人成色77777在线观看| h片在线免费观看| 国产亚洲精品第一综合| 99精品全国免费观看视频 | 在线免费视频一区二区| 一个人看的www免费在线视频| 暖暖免费高清日本一区二区三区| 日本在线观看免费高清| 亚洲AV电影院在线观看| 免费av片在线观看网站| 亚洲色最新高清av网站| 夜夜爽免费888视频| 成人av片无码免费天天看| 亚洲一区二区三区国产精品|