码迷,mamicode.com
首页 > 其他好文 > 详细

每日记载内容总结40

时间:2014-12-09 19:10:17      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   os   使用   sp   

1.ajax传值map时,在页面解析

Map<Integer, List<Object[]>> objs = new HashMap<Integer, List<Object[]>>();
objs.put(1, page.getRows());
objs.put(2, pageOrders);
return renderMyPageData(success, msg, objs, page);
if(result.status == "true" || result.status == true){
                        var page = result.page;
                        var orders = null;
                        var rows = null;
                         $.each(result.data, function(key, value) {
                             if(key == 1){
                                 orders = value;
                             }else if(key == 2){
                                rows =     value;                         
                             }
                         });

2.object转型int

Integer.valueOf(String.valueOf(obj[1])).intValue();

3.js有用方法:

格式化时间

//格式化CST日期的字串
function formatCSTDate(strDate,format){
  return formatDate(new Date(strDate),format);
}
 
//格式化日期,
function formatDate(date,format){
  var paddNum = function(num){
    num += "";
    return num.replace(/^(\d)$/,"0$1");
  }
  //指定格式字符
  var cfg = {
     yyyy : date.getFullYear() //年 : 4位
    ,yy : date.getFullYear().toString().substring(2)//年 : 2位
    ,M  : date.getMonth() + 1  //月 : 如果1位的时候不补0
    ,MM : paddNum(date.getMonth() + 1) //月 : 如果1位的时候补0
    ,d  : date.getDate()   //日 : 如果1位的时候不补0
    ,dd : paddNum(date.getDate())//日 : 如果1位的时候补0
    ,hh : date.getHours()  //
    ,mm : date.getMinutes() //
    ,ss : date.getSeconds() //
  }
  format || (format = "yyyy-MM-dd hh:mm:ss");
  return format.replace(/([a-z])(\1)*/ig,function(m){return cfg[m];});
} 

字符串开端

String.prototype.startWith=function(s){
  if(s==null||s==""||this.length==0||s.length>this.length)
   return false;
  if(this.substr(0,s.length)==s)
     return true;
  else
     return false;
  return true;
 }

4.浏览器下载中文文件名文件时,Firefox会出现乱码,兼容firefox ie8-ie11 chrome的方法:

前端页面,判断浏览器类型,然后传标志位到后台,根据标志位设置内容

var browser = new Object();
browser.isMozilla = (typeof document.implementation != ‘undefined‘) && (typeof document.implementation.createDocument != ‘undefined‘) && (typeof HTMLDocument != ‘undefined‘)? true : false;
browser.isIE = window.ActiveXObject ? true : false;
browser.isOpera = navigator.userAgent.toLowerCase().indexOf(‘opera‘) != -1;
browser.isSafari = navigator.userAgent.toLowerCase().indexOf(‘safari‘) != -1;
browser.isFirefox = navigator.userAgent.toLowerCase().indexOf(‘firefox‘) != -1;
//导出全部二维码
function exporterweima() {
   if(browser.isFirefox){
      window.open(‘${ctx}/exporterweima.do?browserType=1‘);
      }else{
         window.open(‘${ctx}/exporterweima.do?browserType=0‘);
      }
   }
 try {
                // path是指欲下载的文件的路径。
                File file = new File(path);
                // 取得文件名。
                String filename = file.getName();
                // 取得文件的后缀名。
                String ext = filename.substring(filename.lastIndexOf(".") + 1).toUpperCase();
                
                String allName = "";
                if(StringUtils.isNotBlank(province)){
                    allName = province + "---销售二维码." + ext.toLowerCase();
                }else{
                    allName = "销售二维码." + ext.toLowerCase();
                }

                // 以流的形式下载文件。
                InputStream fis = new BufferedInputStream(new FileInputStream(path));
                byte[] buffer = new byte[fis.available()];
                fis.read(buffer);
                fis.close();
                // 清空response
                response.reset();
                // 设置response的Header
                if(browserType != null){
                    if(browserType == 1){
              //针对Firefox设置编码 response.addHeader("Content-Disposition", "attachment;filename="+ new String(allName.getBytes("GB2312"),"ISO-8859-1")); }else{ response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(allName, "UTF-8")); } }else{ response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(allName, "UTF-8"
)); } response.addHeader("Content-Length", "" + file.length()); OutputStream toClient = new BufferedOutputStream(response.getOutputStream()); response.setContentType("application/x-tar"); toClient.write(buffer); toClient.flush(); toClient.close(); f.delete(); } catch (IOException ex) { ex.printStackTrace(); }

5.打包文件

使用ant包打包文件,可以设置编码格式,在linux下,设置编码格式,打包中文文件名的时候,不会乱码。

org.apache.tools.zip.ZipOutputStream使用的默认编码是系统编码(window是gbk而linux是utf- 8),在window下解压时用的是gbk,因些如果是在linux下压缩的文件,到window下解压就会出现乱码,因些在压缩时就为其指定编码为 gbk

(原链接:ZipOutputStream 文件中文乱码

String targetName = resourcesFile.getName()+".rar";   //目的压缩文件名
        //FileOutputStream outputStream = new FileOutputStream(targetPath+"\\"+targetName);
        FileOutputStream outputStream = new FileOutputStream(targetPath+File.separator+targetName);
        ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(outputStream));
        out.setEncoding("GBK");
        createCompressedFile(out, resourcesFile, "");
        //删除erweima文件夹下面的图片
        String[] tempList = resourcesFile.list();
        File temp = null;
        for (int i = 0; i < tempList.length; i++) {
           if (resourcesPath.endsWith(File.separator)) {
              temp = new File(resourcesPath + tempList[i]);
           } else {
               temp = new File(resourcesPath + File.separator + tempList[i]);
           }
           if (temp.isFile()) {
              temp.delete();
           }
        }
        //
        out.close(); 

 

每日记载内容总结40

标签:style   blog   http   io   ar   color   os   使用   sp   

原文地址:http://www.cnblogs.com/cuiyf/p/4153730.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!