dwr 获取HttpSession、request、response等对象
1. 使用DWR的API
- org.directwebremoting.WebContext wc = org.directwebremoting.WebContextFactory.get();
- javax.servlet.http.HttpServletRequest request = wc.getHttpServletRequest();
- javax.servlet.http.HttpServletResponse response = wc.getHttpServletResponse();
- javax.servlet.ServletContext context = wc.getServletContext();
- javax.servlet.ServletConfig config = wc.getServletConfig();
- javax.servlet.http.HttpSession session = wc.getSession();
2.在Java方法中定义这些类型的参数,让DWR自动传入:
例如:
java端方法:
- login(String id, String name, HttpSession session){
- String loginId = (String)session.getAttribute("loginId ");
- }
js调用:login("id","name",callBack)
在js端不用传入session这个参数,DWR自己会将这些参数传入,在java端可以直接调用。
本文详细介绍了使用DWR的API获取HTTP Session、request、response等对象的方法,包括Java代码示例及JS调用方式,实现前端与后端数据交互。

6914

被折叠的 条评论
为什么被折叠?



