免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項超值服

開通VIP
DWR中取得session等信息(轉(zhuǎn)) - 陽光e站------Sunsoft Team ...
關(guān)鍵字: dwr

DWR Java API

There are only 2 Java classes that you commonly need to depend on within DWR as a user - WebContext and WebContextFactory. In DWR 1.x these are in the uk.ltd.getahead.dwr package, for DWR 2.0 onwards they are in org.directwebremoting. These classes give you to access to the standard HTTP servlet objects:

    * HttpServletRequest
    * HttpServletResponse
    * HttpSession
    * ServletContext
    * ServletConfig

You use WebContext like this:

import uk.ltd.getahead.dwr.WebContext;
import uk.ltd.getahead.dwr.WebContextFactory;
///
WebContext ctx = WebContextFactory.get();
req = ctx.getHttpServletRequest();

It is important that you treat the HTTP request and response as read-only. While HTTP headers might get through OK, there is a good chance that some browsers will ignore them (IE ignores cache pragmas for example) Any attempt to change the HTTP body WILL cause DWR errors.

WebContext uses a ThreadLocal variable so you can use the line above anywhere in your code (so long as it has been fired off by DWR).

See also the JavaDoc for DWR in general, or the specific page for WebContext.

WebContext replaces ExecutionContext which is deprecated as of DWR 1.1.
Alternative Method

It is possible to get access to the HTTP servlet objects without writing code that depends on DWR - just have the needed parameter (i.e. HttpServletRequest, HttpServletResponse, HttpSession, ServletContext or ServletConfig) declared on your method. DWR will not include it on the generated stub and upon a call of the method it will fill it in automagically.

For example if you have remoted a class like this:

public class Remote {
  public void method(int param, ServletContext cx, String s) { ... }
}

Then you will be able to access it from Javascript just as though the ServletContext parameter was not there:

Remote.method(42, "test", callback);

DWR will do the work of filling in the parameter for you.

There is one slight caveat with this method. You should ensure you are not using the 'callback function as first parameter' idiom, instead use the 'callback as last parameter' or 'callback in meta-data object' idioms. See the scripting introduction

----------------------------------------------------------------------

最近我們的項目決定采用Ajax技術(shù)實(shí)現(xiàn)一些功能,最后采用了DWR.在使用DWR的時候,遇到了要獲取session中保存的用戶信息的問題.上網(wǎng)查了一下資料,測試成功后簡單記錄起來.

在DWR中需要用到session,request等這些東西的時候,可以用以下方法獲取:
1. 使用DWR的API (很多人都不推薦這種做法,經(jīng)測試,使用起來肯定沒問題)
WebContext ctx = WebContextFactory.get();
ctx.getSession()
ctx.getHttpServletRequest()
...

2. 在Java的服務(wù)方法中定義這些類型的參數(shù),讓DWR自動傳入相應(yīng)的對象:
HttpServletRequest,HttpServletResponse,HttpSession,ServletContext,ServletConfig.
示例如下:
Java端定義方法: saveOrder(String id, String name, HttpSession session)
Javascript調(diào)用: OrderService.saveOrder(jsID,jsName,callBack)
注意,這里不需要傳入session這個參數(shù),DWR會自動傳入,在Java端可以直接使用. 

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Struts2操作Request、Session和Application對象 - juanming5612的日志 - 網(wǎng)易博客
Servlet的多線程安全問題
DWR學(xué)習(xí)筆記(四)
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服