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

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

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

    Vikings

    調用jsonrpc的技巧

    一段不用每個jsp頁面都JSONRPCBridge.registerObject的方法

    1. JsonContextLinster
    在spring文件里讀取需要注冊bridge的bean名單
    registerObject
    public class JSONContextListener implements ServletContextAttributeListener {
        
    private final Log log = LogFactory.getLog(JSONContextListener.class);

        
    public void attributeAdded(ServletContextAttributeEvent event) {
            
    if (event.getName().equals(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)) {
                
    // register LookupHelper so we can call methods on it
                ApplicationContext ctx = (ApplicationContext) event.getValue();

                
    // check for null so we don't have to initialize Spring in tests
                if (ctx != null{
                    log.debug(
    "Registering jsonObjects for XmlHttpRequest to GlobalBridge");
                    
                    JSONRPCBridge jsonBridge 
    = JSONRPCBridge.getGlobalBridge();

                    Map jsonObjects 
    = (Map) ctx.getBean("jsonObjects");
                    
    for (Object name : jsonObjects.keySet()) {
                        jsonBridge.registerObject(name, jsonObjects.get(name));
                    }

                    
                }

            }
            
        }

    public void attributeReplaced(ServletContextAttributeEvent event) {
            attributeAdded(event);
        }

    }


    2.spring配置里的jsonObject
        <!-- json registration -->
        
    <bean name="jsonObjects" class="java.util.HashMap">
            
    <constructor-arg>
                
    <map>
                    
    <entry key="information" value-ref="informationJson"></entry>
                
    </map>
            
    </constructor-arg>
        
    </bean> 

        
    <bean id="informationJson" class="com.vikings.tools.json.Information" >
            
    <property name="informationDAO" ref="informationDAO" />
        
    </bean>

    3.web.xml里增加配置剛才寫的listener
    <listener>
            
    <listener-class>com.vikings.tools.json.JSONContextListener</listener-class>
        
    </listener>

    到這里就不用這么寫了
    <jsp:useBean id="JSONRPCBridge" scope="session"
       class
    ="com.metaparadigm.jsonrpc.JSONRPCBridge" />

    <% JSONRPCBridge.registerObject("myTestObject", aTestObject); %>
    這個也不需要
    // Find the JSONRPCBridge for this session or create one
    // if it doesn't exist. Note the bridge must be named "JSONRPCBridge"
    // in the HttpSession for the JSONRPCServlet to find it.
    HttpSession session = request.getSession();
    JSONRPCBridge json_bridge 
    = null;
    json_bridge 
    = (JSONRPCBridge) session.getAttribute("JSONRPCBridge");
    if(json_bridge == null{
        json_bridge 
    = new JSONRPCBridge();
        session.setAttribute(
    "JSONRPCBridge", json_bridge);
    }

    posted on 2007-11-01 22:19 Vikings 閱讀(1476) 評論(0)  編輯  收藏


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


    網站導航:
     
    主站蜘蛛池模板: 粉色视频免费入口| 国产亚洲蜜芽精品久久| 久艹视频在线免费观看| 亚洲精品国产日韩无码AV永久免费网| 亚洲AV香蕉一区区二区三区| 午夜视频免费观看| 亚洲国产成人AV在线播放| 全免费一级毛片在线播放| 亚洲高清有码中文字| 热99re久久免费视精品频软件 | 亚洲?V乱码久久精品蜜桃| 国产成人高清亚洲一区久久 | 日本亚洲视频在线| 女同免费毛片在线播放| 久久久亚洲精品无码| 4399影视免费观看高清直播| 亚洲国产夜色在线观看| 超pen个人视频国产免费观看| 国产亚洲成在线播放va| 红杏亚洲影院一区二区三区| a毛片视频免费观看影院| 久久综合亚洲鲁鲁五月天| 91免费精品国自产拍在线不卡| 亚洲一区二区三区国产精品无码 | 白白国产永久免费视频| 免费看一级毛片在线观看精品视频| 国产一区二区三区免费视频| 日韩在线视频线视频免费网站| 区久久AAA片69亚洲| 69av免费观看| 无忧传媒视频免费观看入口| 精品亚洲永久免费精品| 很黄很黄的网站免费的| 美女免费视频一区二区三区| 亚洲精品卡2卡3卡4卡5卡区| xxxx日本免费| 一级成人毛片免费观看| 亚洲短视频在线观看| 免费一级黄色毛片| 在线日本高清免费不卡| 理论秋霞在线看免费|