路径带jsessionid,比如/login;jsessionid=,jFinal报404

路径带jsessionid,比如/login;jsessionid=,jFinal报404,实际有servlet对应/login,请问如何解决?

建议JFinalFilter中

String target = request.getRequestURI();

if (contextPathLength != 0)

target = target.substring(contextPathLength);

修改为

String target = request.getServletPath();

评论区

JFinal

2017-10-31 23:57

用一下这个 handler 即可打完收工:
https://github.com/ChunMengLu/Easy4JFinal/blob/master/easy-core/src/main/java/net/dreamlu/easy/handler/SessionIdHandler.java

camus213

2017-11-01 11:32

@JFinal 谢谢,加handler,技能Get!

阿普

2017-12-13 16:19

@JFinal 该解决方案不够完美,仍然可能会报404, 建议老大在jfinal中修复该问题,以下是在原来基础上改动的。


import com.jfinal.handler.Handler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* @author lsup
* 解决url上带有sessionId可能报404
*/
public class SessionIdHandler extends Handler {
@Override
public void handle(String target, HttpServletRequest request, HttpServletResponse response, boolean[] isHandled) {
boolean hasSessionIdInURL = request.isRequestedSessionIdFromURL() && request.isRequestedSessionIdFromCookie();
if (hasSessionIdInURL) {
int index = target.indexOf(";");
if (index > 0) {
target = target.substring(0, index);
}
}
next.handle(target, request, response, isHandled);
}
}

JFinal

2017-12-13 16:32

@阿普 已提交 issue: https://gitee.com/dreamlu/Easy4JFinal/issues/IGSOH

感谢你的反馈

阿普

2017-12-13 17:36

上面写错了 应该是 boolean hasSessionIdInURL = request.isRequestedSessionIdFromURL() || request.isRequestedSessionIdFromCookie();

飞鱼开发者

2018-07-19 11:01

@阿普 很有用~~谢谢啦~

热门反馈

扫码入社