我们实现了一些servlet,JSP和过滤器,一切都是 到目前为止工作正常。我不想跟踪下一个2-3的一个requestURL 请求,我不能在会话中保存这个,因为我们正在使用session 登录目的。但是当我们尝试在请求中设置属性时 对象并从JSP中读取它,我们总是得到空值。
在过滤器类中,我们执行以下操作:
String url = ((HttpServletRequest)req).getRequestURL().toString();
if(url.contains("asc/ascHome")){
HttpServletRequest request = (HttpServletRequest) req;
request.setAttribute("OriginURL", "AscHome");
}
chain.doFilter(request, response);
> In our login.jsp, we are using the following code to retrieve the
> attribute:
String originURL = request.getAttribute("OriginURL").toString();
> Is there anything we're missing?
>
> Filter is as below,
public class SessionAlertFilter implements Filter {
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain filterChain)
throws IOException, ServletException {
HttpServletResponse httpResp = (HttpServletResponse) resp;
HttpServletRequest httpReq = (HttpServletRequest) req;
HttpSession session = httpReq.getSession();
String str_session_id = session.getId();
//System.out.println(" session.getMaxInactiveInterval() :"+session.getMaxInactiveInterval());
long currTime = System.currentTimeMillis();
//long expiryTime = currTime + (2*60 * 1000); //25 minutes considering 30 minutes is session timeout
long expiryTime = currTime + ((session.getMaxInactiveInterval() * 1000) - (5*60*1000));
Cookie cookie = new Cookie("serverTime", "" + currTime);
cookie.setPath("/");
httpResp.addCookie(cookie);
//SessionObj session_obj = (SessionObj) session.getAttribute("session_obj");
if (str_session_id != null) {
//System.out.println("session id2------"+str_session_id+" expiryTime: "+expiryTime);
//showTime(expiryTime);
cookie = new Cookie("sessionExpiry", "" + expiryTime);
} else {
cookie = new Cookie("session id2------"+str_session_id+" sessionExpiry", "" + currTime);
//showTime(expiryTime);
//System.out.println("currTime: "+currTime);
}
cookie.setPath("/");
((HttpServletResponse) resp).addCookie(cookie);
String url = ((HttpServletRequest)req).getRequestURL().toString();
System.out.println("In Filter.... URL : "+url);
if(url.contains("asc/AscHome.jsp")){
req.setAttribute("OriginURL", "Register_Call");
}
filterChain.doFilter(req, resp);
//checkCookie(httpReq);
}