|

楼主 |
发表于 2018-1-12 10:13:23
|
显示全部楼层
- public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- System.out.println("在测试");
- JSONObject content = null;
- String bsessionid = "";
-
- //从cookie中获取已有的bsessionid
- Cookie[] cookies = request.getCookies();
- if (cookies != null){
- for (int i = 0; i < cookies.length; i++) {
- String name = cookies[i].getName();
- if(name.equals("bsessionid")){
- bsessionid = cookies[i].getValue();
- }
- }
- }
-
-
- //判断bsessionid是否超时
- ActionResult checkResult = ActionEngine.checkSession(bsessionid, ActionUtils.JSON_CONTENT_TYPE);
- if (checkResult.isSessionTimeOut()) {
-
- String username =request.getParameter("username");
- String password =request.getParameter("password");
- String ip = request.getRemoteAddr();
- String language = "zh_CN";
- Date loginDate = new Date(System.currentTimeMillis());
- ActionResult actionResult = ActionEngine.login2(username, password, ip, language, loginDate, null, ActionUtils.JSON_CONTENT_TYPE, null);
- content = (JSONObject) actionResult.getContent();
- bsessionid = actionResult.getBSessionID();
- System.out.println("bsessionid:"+bsessionid);
- //把bsessionid放到Cookie中
- Cookie cookie = new Cookie("bsessionid",bsessionid);
- cookie.setMaxAge(-1);
- cookie.setPath("/");
- response.addCookie(cookie);
-
- response.getWriter().write(bsessionid);
- } else {
- content = (JSONObject) checkResult.getContent();
- }
-
-
- content.put("bsessionid", bsessionid);
- response.setCharacterEncoding("UTF-8");
- response.addHeader("Access-Control-Allow-Origin", "*");
- response.setContentType(ActionUtils.JSON_CONTENT_TYPE);
-
- response.sendRedirect("/x5/UI2/Cases/Demo/process/Test/mainActivity.w");
-
- response.flushBuffer();
-
- }
复制代码 使用.j访问 还是会报 当前用户不在在线用户列表中! 的错误
- http://127.0.0.1:8080/x5/UI2/Cases/Demo/process/Test/login.j?password=123456&username=system
复制代码
|
|