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

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

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

    gdufo

     

    實戰(zhàn)Struts-Menu(3)

     插入測試數(shù)據(jù):
    INSERT INTO menu_item
        (id
    , parent_name, name, title, titleCN, location)
    VALUES
        (
    1,null,'DatabaseMenu','Database Menu','數(shù)據(jù)庫動態(tài)菜單',null),
        (
    2,'DatabaseMenu','Yahoo','Yahoo Mail','雅虎郵件','http://mail.yahoo.com'),
        (
    3,'DatabaseMenu','JavaBlogs','JavaBlogs','Java博客','http://javablogs.com'),
        (
    4,null,'StandaloneMenu','Standalone Menu','獨立的菜單','http://www.sohu.com')
    > 將數(shù)據(jù)庫驅(qū)動程序放到lib目錄中,并加入到Build Path,如MySQL的數(shù)據(jù)庫驅(qū)動mysql-connector-java-3.1.8-bin.jar,解壓縮commons- collections-3.1.zip,將commons-collections-3.1.jar釋放到lib目錄,并加入Build Path
      > 新建一個Struts的Action,代碼如下:

    package cn.appex.menu;

    import java.io.UnsupportedEncodingException;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.ListResourceBundle;
    import java.util.Map;

    import com.mysql.jdbc.Driver;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;

    import net.sf.navigator.menu.MenuComponent;
    import net.sf.navigator.menu.MenuRepository;
    import net.sf.navigator.menu.PermissionsAdapter;

    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;

    public class MenuAction extends Action {
        
    public ActionForward execute(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response)
                
    throws Exception {
            buildMenuRepository(request);
            buildMenuResourceBundle(request);
            buildMenuPermissions(request);
            
    return (mapping.findForward("success"));
        }

        
    /**
         * 創(chuàng)建菜單數(shù)據(jù)結(jié)構(gòu)
         * 
         * 
    @param request
         
    */
        
    private void buildMenuRepository(HttpServletRequest request) {
            MenuRepository repository 
    = new MenuRepository();
            
    // Get the repository from the application scope - and copy the
            
    // DisplayerMappings from it.
            MenuRepository defaultRepository = (MenuRepository) request
                    .getSession().getServletContext().getAttribute(
                            MenuRepository.MENU_REPOSITORY_KEY);
            repository.setDisplayers(defaultRepository.getDisplayers());

            Map[] menus 
    = getMenuComponents();
            
    for (int i=0; i < menus.length; i++) {
                MenuComponent mc 
    = new MenuComponent();
                Map row 
    = menus[i];
                String name 
    = (String) row.get("name");
                mc.setName(name);
                String parent 
    = (String) row.get("parent_name");
                System.out.println(name 
    + ", parent is: " + parent);
                
    if (parent != null) {
                    MenuComponent parentMenu 
    = repository.getMenu(parent);
                    
    if (parentMenu == null) {
                        System.out.println(
    "parentMenu '" + parent + "' doesn't exist!");
                        
    // create a temporary parentMenu
                        parentMenu = new MenuComponent();
                        parentMenu.setName(parent);
                        repository.addMenu(parentMenu);
                    }

                    mc.setParent(parentMenu);
                }
                String title 
    = (String) row.get("title");
                mc.setTitle(title);
                String location 
    = (String) row.get("location");
                mc.setLocation(location);
                String description 
    = (String) row.get("description");
                mc.setDescription(description);
                repository.addMenu(mc);
            }
            
            request.setAttribute(
    "examplesRepository", repository);
        }

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

    導(dǎo)航

    統(tǒng)計

    常用鏈接

    留言簿(6)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    收藏夾

    Hibernate

    友情鏈接

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲AV成人片色在线观看高潮| 国产成人精品日本亚洲专一区| 亚洲爆乳无码专区www| 青青视频观看免费99| 亚洲天堂一区在线| 亚洲日韩在线中文字幕综合 | 韩国18福利视频免费观看| 亚洲一区二区三区久久久久| 四虎永久在线精品免费观看视频| 亚洲美免无码中文字幕在线| 青青青亚洲精品国产| 四虎在线播放免费永久视频 | 久久精品国产亚洲av天美18| 四虎影视精品永久免费| 五级黄18以上免费看| 国产亚洲人成网站在线观看不卡| 亚洲免费观看视频| 亚洲色av性色在线观无码| 精品国产无限资源免费观看| 亚洲中文字幕无码一区| 久久国产乱子伦精品免费一| 亚洲日韩国产一区二区三区| A级毛片成人网站免费看| 久久久综合亚洲色一区二区三区 | 亚洲国产精品久久久天堂| 亚洲成av人无码亚洲成av人| 免费在线观看a级毛片| baoyu777永久免费视频| 亚洲视频欧洲视频| 日韩免费高清视频| 精品国产呦系列在线观看免费| 亚洲AV日韩精品久久久久| 女人张腿给男人桶视频免费版| 一级毛片人与动免费观看 | 亚洲乱码在线观看| 亚洲国产成人精品无码久久久久久综合 | 亚洲精品成人图区| 免费看男女下面日出水视频| 久久九九全国免费| 婷婷国产偷v国产偷v亚洲| 亚洲天堂久久精品|