public URL getUrl(HttpServletRequest req) throws IOException { String servletPath = req.getServletPath(); String selectedServerFullPath = getServerAddress(servletPath); String queryString = req.getQueryString(); String newUrl = ""; HttpSession session = req.getSession(false); newUrl = selectedServerFullPath + servletPath; if (req.getRequestedSessionId() != null) newUrl = newUrl + ";jsessionid=" + req.getRequestedSessionId(); if (queryString != null) newUrl = newUrl + "?" + queryString; // if (session != null) newUrl = newUrl + ";jsessionid=" + session.getId(); return new URL(newUrl); }