These days I have to upload and download a page. I have been struggling with uploading and downloading pages for years and thought it was an Extjs-based upload and download. In fact, it has nothing to do with Extjs, this is only because the thinking has been confined to the Extjs interface. I heard that Extjs4.0 has corresponding controls, because the current company project... syntaxHighlighter. all (); the upload and download of a page over the past few days have been entangled until now. I thought it was an upload and download under Extjs, but it has nothing to do with Extjs, this is only because the thinking has been confined to the Extjs interface. I heard that Extjs4.0 has a corresponding control. The current project is not 4.0, so it has not been implemented yet. Below we record the solution we have summarized. Upload: [javascript] {xtype: 'textfield', fieldLabel: 'upload file', name: 'userfile', id: 'userfile', inputType: 'file', width: 300, height: 20 // emptyText: 'Select Upload file... 'I don't know why these two parameters are invalid in IE8. // blankText: 'file can \' t not empty. '} upload triggered by a Button: [javascript] {xtype: 'button', text: 'upload', name: 'doc _ upbut ', id: 'doc _ upbut ', handler: function () {if (form. form. isValid () {var upFile = Ext. get Cmp ('userfile '). getValue (); if (upFile = '') {Ext. msg. alert ('error', 'select the file you want to upload '); return;} var upFileLastName = upFile. toString (); var LastNames = upFileLastName. split ("\. ") if (LastNames [LastNames. length-1] = ("exe") {Ext. msg. alert ('error', 'this type of file is not supported! '); Return;} var file_up = document. getElementById ('userfile'); file_up.select (); var realpath = document. selection. createRange (). text; realpath = encodeURIComponent (realpath); // a virtual path will appear above IE8. Obtain the real path Ext here. messageBox. show ({title: 'Please wait a moment ', msg:' the file is being uploaded... ', progressText: '', width: 300, progress: true, closable: false, animEl: 'loding'}); Ext. ajax. request ({url :'.. /control/IndexDocument? Act = updateLoad ', params: {filePath: realpath, fatherPath: doc_majorCode}, method: 'post', success: function (request) {var resp = Ext. util. JSON. decode (request. responseText); if (resp. success = 'fail ') {Ext. msg. alert ('info ',' Upload Failed!
'+ Resp. Info +'
');} Else {Ext. Msg. alert ('hup', 'upload successful! '); Doc_store.reload (); doc_grid.getView (). refresh (); doc_store.commitChanges () ;}}, failure: function (result, request) {Ext. msg. alert ('error', 'unknown error occurred during upload. ') ;}}}}handler processing: [java] public String updateLoad (HttpServletRequest request, HttpServletResponse response) {String jsonData = ""; String frompage = ""; try {String path = request. getSession (). getServletContext (). getRealPath (rootDir); Str Ing filePath = URLDecoder. decode (request. getParameter ("filePath"), "UTF-8"); String fatherPath = request. getParameter ("fatherPath"); frompage = (request. getParameter ("frompage ")! = Null )? Request. getParameter ("frompage"): ""; jsonData = docUtil. updateLoad (filePath, fatherPath, path);} catch (UnsupportedEncodingException e) {e. printStackTrace (); jsonData = e. getMessage () ;}if (! JsonData. equalsIgnoreCase ("") {jsonData = "{success: 'fail ', Info:'" + jsonData + "'}";} else {jsonData = "{success: 'success', Info: 'upload successful! '} ";} Request. setAttribute ("jsonData", jsonData); if (frompage. equals ("") {return "extDataPage";} else if (frompage. equals ("downloadFileListPage") {return downloadFileList (request, response) ;}else {return frompage ;}} docUtil processing: [java] public String updateLoad (String filePath, String fatherPath, string path) {String ret = ""; File upFileDir = new File (path + "\" + fatherPath); if (! UpFileDir. exists () {upFileDir. mkdirs ();} String s [] = filePath. split ("\\\\"); String fileName = s [s. length-1]; File inFile = new File (filePath); File outFile = new File (upFileDir. getPath () + "\" + fileName); FileInputStream FCM; FileOutputStream fos; BufferedInputStream bis = null; BufferedOutputStream bos = null; try {FD = new FileInputStream (inFile ); fos = new FileOutputStream (outFile); bis = New BufferedInputStream (FCM); bos = new BufferedOutputStream (fos); byte [] B = new byte [1024]; int len; while (len = bis. read (B ))! =-1) {bos. write (B, 0, len);} bos. flush ();} catch (FileNotFoundException e) {e. printStackTrace (); ret = "File Upload Failed! ";} Catch (IOException e) {e. printStackTrace (); ret =" An error occurred while uploading the file! ";}Finally {www.2cto.com try {bis. close (); bos. close () ;}catch (IOException e) {e. printStackTrace () ;}} return ret ;}