Java servlet sessions within multiple iframes -
i have site, call www.main.com 4 iframes loads www.iframe.com/foo each of iframes. upon initial load of www.iframe.com/foo make call config.bar() servlet (foo) load user data session. before make call config.bar() i'm checking see if config loaded session , if so, skip fetch config.bar() , load session.
my problem is, since session not yet established in foo, getting 4 unique session id's, making 4 calls config.bar(). when refresh www.main.com page, 4 iframes load again assigned sessionid of first iframe load (from previous request).
i tried moving logic filter hoping right things had no effect. possible load servlet multiple times within iframes different url , have 1 session id @ time of initial load?
here's snippets demonstrate i'm trying do:
www.iframe.com/foo:
//--foocontroller.java @controller class foocontroller { @requestmapping(value = "/foo", method = requestmethod.get) public string foo(model model, httpservletrequest request) { config c = request.getsession().getattribute("config"); reqest.setattribute("bazz", bazz.domagic(c)); return "foo"; } } //--configfilter.java public class configfilter implements filter { @autowired private configservice cs; public void init(filterconfig config) throws servletexception { } public void dofilter(servletrequest request, servletresponse response, filterchain chain) throws java.io.ioexception, servletexception { httpservletrequest req = (httpservletrequest) request; httpsession sess = req.getsession(); //first request these different each iframe //second request match system.out.println("sess="+sess.getid()); //only fetch config if not in session if(sess.getattribute("config") == null) { sess.setattribute("config", cs.getcfg()); // pass request down filter chain chain.dofilter(request,response); } public void destroy() { } }
www.main.com:
<html> <body> <iframe src="http://www.iframe.com/foo?page=1"></iframe> <iframe src="http://www.iframe.com/foo?page=2"></iframe> <iframe src="http://www.iframe.com/foo?page=3"></iframe> <iframe src="http://www.iframe.com/foo?page=4"></iframe> </body> </html>
Comments
Post a Comment