DWR session获取方法
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端可以直接调用。