平台默认的打开首页的时候会从Cookie中获取bsessionid
第三方集成登录时不在跳转的首页地址后加username和password或者bsessionid参数就直接打开登录后的首页,可以在登录后把bsessionid放到Cookie中
实现登录的.j如下:
import java.io.IOException; import java.sql.Date; import javax.servlet.ServletException; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.alibaba.fastjson.JSONObject; import com.justep.biz.client.ActionEngine; import com.justep.biz.client.ActionResult; import com.justep.biz.client.ActionUtils; public class Login extends com.justep.ui.impl.JProcessorImpl { public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 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(); //把bsessionid放到Cookie中 Cookie cookie = new Cookie("bsessionid",bsessionid); cookie.setMaxAge(-1); cookie.setPath("/"); response.addCookie(cookie); } 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/portal/pc3/index.w"); response.flushBuffer(); } }
评一波