您的位置:首页 > Web前端 > CSS

java web项目发版js或css缓存问题解决方案

2016-12-15 09:20 471 查看
java web项目发版js或css缓存问题解决方案

给引入的js或css文件加版本号



<%

 String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";

    // 加载资源文件

    PropertiesResourceFileUtils prfu = new PropertiesResourceFileUtils("version.properties");

%>

<script type="text/javascript" src="<%=basePath%>script/common/common.js?version=<%=prfu.getValue("version") %>"></script>

<link rel="stylesheet" type="text/css" href="<%=basePath%>css/epoch.css?version=<%=prfu.getValue("version") %>">

version.properties文件:

#版本号

version=20161125.02

public class PropertiesResourceFileUtils {

 /**

  * Properties对象

  */

 private Properties properties = new Properties();

 

 /**

  * PropertiesResourceFileUtils构造函数

  * @param propertiesPath 文件路径

  */

 public PropertiesResourceFileUtils(String propertiesPath) {

        try {

            InputStream in = PropertiesResourceFileUtils.class.getClassLoader().getResourceAsStream(propertiesPath);

            if(in != null) {

                properties.load(in);

            }

        }

        catch (IOException e) {

            e.printStackTrace();

        } 

 }

    /**

     * 通过KEY获取值

     * @param key

     * @return 

     */

    public String getValue(String key){

        String value = properties.getProperty(key);

        if(StringUtils.isNotBlank(value))

            try {

                value = new String(value.getBytes("ISO-8859-1"), "UTF-8");

            } catch (UnsupportedEncodi
4000
ngException e) {

                e.printStackTrace();

            }

        return value;

    }

}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: