Joke Collection Website - Blessing messages - jquery gets the full path of fileupload. Give the complete code.

Can be used directly

jquery gets the full path of fileupload. Give the complete code.

Can be used directly

1 First is jsp

lt; button class="btn button uploadAndNext" id="importWhiteBtn" type="button"gt;

lt; span class="button"gt;Submit importlt;/spangt;

lt;/buttongt;

2. Then js

$(function() {

var uploadCom = null;

function uploadIt() {

$("#importWhiteBtn").click(function() {

var uploadId = "#" $(this).attr("id");

var btn = $(this);

uploadCom = new AjaxUpload( uploadId " " , {

action: "whitePhoneNumber.do?action=importFile",

onSubmit: function(file, ext) {

if ((ext amp ;amp; /^(txt)$/.test(ext))) {

alert("Please download the import template readme.txt for reference first. The format of the document you uploaded is wrong, please choose again!" );

return false;

}

$.blockUI({

message: "Uploading to server.... "

})

},

onComplete: function(file, response) {

$.unblockUI();

p>

if(response=="success"){

alert( "Import successful");

$('#whitePhoneList').flexReload();

}else{

alert( "Import failed," response);

}

}

});

});

$(".uploadAndNext").click();

}

uploadIt() ;

firstClick = false;

})

3. Finally, action

public ActionForward importFile(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response) throws Exception{

FileItemFactory factory = new DiskFileItemFactory();

ServletFileUpload upload = new ServletFileUpload(factory);

String success = "success";

BufferedReader br=null;

InputStream in=null;

String operator = UserNameUtil.getUserName(request );

String areaCode = whitePhoneManager.getAreaCodeByOperator(operator);

try {

Listlt; FileItemgt; list = upload.parseRequest(request);

p>

for (int i = 0; i lt; list.size(); i ) {

FileItem fileItem = list.get(i);

String name = fileItem.getName().substring(

fileItem.getName().lastIndexOf("\\") 1);

if(fileItem.getSize() gt; 2097152) {//200k

throw new Exception("File size exceeds 2M");

}

log.debug("upload file name:" name) ;

in= fileItem.getInputStream();

br = new BufferedReader(new InputStreamReader(in));

whitePhoneManager.processFile(br, areaCode) ;

logutil.log_Operation(request, LogUtil.LOG_MODULE_SYSTEMCONFIG,

LogUtil.LOG_EVENT_CREATE,

"Batch import SMS whitelist", "filename: "

name, "Success",

LogUtil.SUCCESS);

}

} catch (FileUploadException e) {

log.debug("error", e);

success=e.getMessage();

} catch (Exception e) {

log.debug("error", e);

success=e.getMessage();

}finally{

if(br!=null) try{br.close();}catch(Exception e){log.error("unable to close bufferdreader", e);}

if(in!=null) try{in.close();}catch(Exception e){log.error("unable to close inputstream",e);}

response.setContentType("text /html");

response.setCharacterEncoding("UTF-8");

response.getWriter().write( success );

return null ;

}

}