w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Getting HTTP serverName and serverPort from HttpSession

Well, it is kind of a hack, but as suggested by Jorge Campos, you could use a Filter to put a pointer to the request into the session at the beginning and remove it at the end. Something like :

public class ReqFilter implements Filter {
    ...
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {

        HttpSession session = ((HttpServletRequest) request).getSession();
        session.setAttribute("request", request);
        try {
            chain.doFilter(request, response);
        }
        catch(IOException e) {
            throw e;
        }
        catch(ServletException e) {
            throw e;
        }
        finally {
            session.setAttribute("request", null);
        }
    }
}




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.