1.ajax value map, in page parsing
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){ varpage =Result.page; varOrders =NULL; varrows =NULL; $.each (Result.data,function(key, value) {if(Key = = 1) {orders=value; }Else if(Key = = 2) {rows=value; } });
2.object Transformation int
Integer.valueof (String.valueof (obj[1])). Intvalue ();
3.js Useful methods:
Format time
//format a string for the CST datefunctionformatcstdate (strdate,format) {returnFormatDate (NewDate (strdate), format);} //format date,functionFormatDate (date,format) {varPaddnum =function(num) {num+= ""; returnNum.replace (/^ (\d) $/, "0$1"); } //Specify format characters varCFG ={yyyy:date.getFullYear ()//year: 4 guests, Yy:date.getFullYear (). toString (). SUBSTRING (2)//year: 2 guests, M:date.getmonth () + 1//Month: If 1 bit does not fill 0, Mm:paddnum (Date.getmonth () + 1)//Month: 0 if 1 digits, D:date.getdate ()//Day: If the 1-bit time does not fill 0, Dd:paddnum (Date.getdate ())//Day: 0 if 1 digits, Hh:date.getHours ()//when, Mm:date.getMinutes ()//points, Ss:date.getSeconds ()//seconds} format|| (format = "Yyyy-mm-dd hh:mm:ss"); returnFormat.replace (/([A-z]) (\1) */ig,function(m) {returncfg[m];});}
String start
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. When the browser downloads Chinese file name file, Firefox will appear garbled, compatible with Firefox Ie8-ie11 Chrome method:
Front page, determine browser type, then pass flag to background, set content according to flag bit
varBrowser =NewObject (); Browser.ismozilla= (typeofDocument.implementation! = ' undefined ') && (typeofDocument.implementation.createDocument! = ' undefined ') && (typeofHTMLDocument! = ' 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;
Export all two-dimensional code
function Exporterweima () {
if (Browser.isfirefox) {
window.open (' ${ctx}/exporterweima.do?browsertype=1 ');
}else{
window.open (' ${ctx}/exporterweima.do?browsertype=0 ');
}
}
Try { //Path refers to the paths of the files you want to download. File File =NewFile (path); //gets the file name. String filename =File.getname (); //gets the suffix name of the file. String ext = filename.substring (Filename.lastindexof (".") + 1). toUpperCase (); String Allname= ""; if(Stringutils.isnotblank (province)) {Allname= Province + "---sales qr code." +ext.tolowercase (); }Else{allname= "Sales qr code." +ext.tolowercase (); } //download the file in the form of a stream. InputStream FIS =NewBufferedinputstream (NewFileInputStream (path)); byte[] buffer =New byte[Fis.available ()]; Fis.read (buffer); Fis.close (); //Empty ResponseResponse.reset (); //set the header of the response if (browsertype! = null) {if (BrowserType = = 1) {
Set the encoding Response.AddHeader for Firefox ("Content-disposition", "attachment;filename=" + New String (Allnam E.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.E Ncode (Allname, "UTF-8")); } Response.AddHeader ("Content-length", "" "+file.length ()); OutputStream toclient=NewBufferedoutputstream (Response.getoutputstream ()); Response.setcontenttype ("Application/x-tar"); Toclient.write (buffer); Toclient.flush (); Toclient.close (); F.delete (); } Catch(IOException ex) {ex.printstacktrace (); }
5. Packaging files
Using the ant package file, you can set the encoding format, under Linux, set the encoding format, packaging Chinese file names, will not garbled.
The default encoding used by Org.apache.tools.zip.ZipOutputStream is the System Encoding (window is GBK and Linux is Utf-8), and the GBK is used when extracting under Windows, because if it is compressed under Linux, To the window under the decompression will appear garbled, because some in the compression of the specified encoding for GBK
(Original link:zipoutputstream file Chinese garbled )
String targetName = resourcesfile.getname () + ". rar";//Purpose Compress file name//FileOutputStream outputstream = new FileOutputStream (targetpath+ "\ \" +targetname);FileOutputStream OutputStream =NewFileOutputStream (targetpath+file.separator+targetName); Zipoutputstream out=NewZipoutputstream (NewBufferedoutputstream (OutputStream)); Out.setencoding ("GBK"); Createcompressedfile (out, Resourcesfile,""); //Delete the picture below the Erweima folderstring[] Templist =resourcesfile.list (); File Temp=NULL; for(inti = 0; i < templist.length; i++) { if(Resourcespath.endswith (file.separator)) {temp=NewFile (Resourcespath +Templist[i]); } Else{Temp=NewFile (Resourcespath + file.separator +Templist[i]); } if(Temp.isfile ()) {temp.delete (); } } //Out.close ();
Summary of daily Contents 40