开发者

How to include javascript/css once with Struts 1.x

开发者 https://www.devze.com 2023-01-01 22:22 出处:网络
If this is the wrong approach, please suggest something better, but my current efforts have been trying to find something that exists for a single page load, such that I can cache which javascript/css

If this is the wrong approach, please suggest something better, but my current efforts have been trying to find something that exists for a single page load, such that I can cache which javascript/css files have been included so as to only include them once. I thought in a TagSupport subclass I could use

(HttpServletRequest)pageContext.getRequest().getParameterMap().put(srcKey,true)

but the request is per jsp, not per page load so it was a failure. I could set up a filter in web.xml, but it seems I would have to search the response for duplicates and rewrite the response.开发者_运维百科..pain. I could try to store things in the session, but there are headaches with clearing values... Any help would be appreciated.


The request object is not "per jsp"; it's the request object. You can use the "attributes" map for what you want

pageContext.getRequest().setAttribute(srcKey, Boolean.TRUE);

edit — if you're building a single browser page with multiple HTTP requests, then you'll have to keep track of what scripts are on the page in the client, so that each successive HTTP request can include some sort of hidden parameter to convey the information. Alternatively, you could use the session, but as you said it'll be a mess to maintain.

Perhaps you could explain more about how your pages are constructed.

0

精彩评论

暂无评论...
验证码 换一张
取 消