我在Struts2上有一个拦截器,我想为一些页面重定向到他们的ssl版本。
示例:从http://localhost/xhtml/path.do?ossesionid=value1到https://localhost/xhtml/path.do?ossesionid=value1
为此,我创建了一个拦截器来做这件事:
public String intercept(ActionInvocation invocation) throws Exception {
// initialize request and response
final ActionContext context = invocation.getInvocationContext();
final HttpServletRequest request = (HttpServletRequest) context
.get(StrutsStatics.HTTP_REQUEST);
final HttpServletResponse response = (HttpServletResponse) context
.get(StrutsStatics.HTTP_RESPONSE);
// check scheme
String scheme = request.getScheme().toLowerCase();
// check method
String method = request.getMethod().toUpperCase();
// If the action class uses the SSLProtected marker annotation, then see
// if we need to
// redirect to the SSL protected version of this page
if (invocation.getAction() instanceof SSLProtected) {
if (HTTP_GET.equals(method) && SCHEME_HTTP.equals(scheme)) {
// initialize https port
String httpsPortParam = request.getSession().getServletContext().getInitParameter(HTTP_PORT_PARAM);
int httpsPort = httpsPortParam == null ? HTTPS_PORT : Integer.parseInt(httpsPortParam);
response.setCharacterEncoding("UTF-8");
URI uri = new URI(SCHEME_HTTPS, null, request.getServerName(), httpsPort, response.encodeRedirectURL(request.getRequestURI()), request.getQueryString(), null);
log.debug("Going to SSL mode, redirecting to " + uri.toString());
response.sendRedirect(uri.toString());
return null;
}
}我的问题是我希望
https://localhost/xhtml/path.do?ossesionid=value1并得到了
https://localhost/xhtml/path.do;jsessionid=value1?osessionid=value1我完全迷路了!对谁有帮助吗?
发布于 2012-04-20 03:02:44
我强烈建议您使用S2-SSL plugin,它更灵活,并且提供了更好的支持来处理从SSL到非SSL的切换,反之亦然。
关于Jsessionid的生成,JSESSIONID cookie是在会话创建时创建/发送的。会话是在代码第一次调用request.getSession()或request.getSession(true)时创建的。如果您只想获取session.You,那么有办法禁止创建Jsessionid
您可以通过多种方式禁用此id的创建,请参阅此讨论主题。
我仍然不确定您使用这个session-id会遇到什么问题,因为这在web应用程序中是很常见的情况。
https://stackoverflow.com/questions/10234573
复制相似问题