在DWR调用的java代码中使用Session,Request,Response等
2007-10-29 19:30
746 查看
![]() 输入您的搜索字词 提交搜索表单 |
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
//2007-10-24: csdn.blog
google_ad_channel = "8548491739";
DWR Java APIThere are only 2 Java classes that you commonly need to depend on within DWR as a user -WebContextand WebContextFactory. In DWR 1.x these are in the uk.ltd.getahead.dwrpackage, 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 WebContextlike 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 MethodIt 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 ServletContextparameter 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 |
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
//2007-10-24: csdn.blog
google_ad_channel = "8548491739";
相关文章推荐
- 在DWR调用的java代码中使用Session,Request,Response等
- Java中通过DWR获取session、request、response
- 使用JAVA发送HTTP请求(Http Request),返回HTTP响应(Http Response)内容,代码程序例子及原理说明
- 使用DWR实现JS调用服务端Java代码
- 使用DWR实现JS调用服务端Java代码
- DWR调用后台java方法时获取request、session等对象
- 使用DWR实现JS调用服务端Java代码
- 使用DWR实现JS调用服务端Java代码
- Java中通过DWR获取session、request、response
- CXF之使用工厂方法(java代码)发布服务与进行客户端调用
- SpringMVC中使用@RequestBody,@ResponseBody注解实现Java对象和XML/JSON数据自动转换(上)
- 1.JAVA中使用JNI调用C++代码学习笔记 - 星云博客园
- Android的JS调用Java代码或使用了Javascript相关技术,如何混淆
- 在JAVA中使用response.sendRedirect和使用RequestDispatcher.forward的区别
- flex 中通过 RO 调用一个java写的Bean的时候获得IP地址的方法 .也就是获得session 和 request的方法
- MATLAB Java builder的使用——在JAVA中调用MATLAB代码
- DWR获取,request,response,session等的方法
- Android平台下使用lua调用Java代码经验总结
- java 程序中获取session/request/response/上下文路径等对象
- ScriptEngine使用java调用js代码