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 ;
}
}
- Previous article:Excuse me, how to light the icon of QQ library? Ask god for help
- Next article:How do parents make speeches at their daughter's wedding?
- Related articles
- I am in Caoxin Road, Huaqiao, Kunshan. If I am trapped in Shanghai, is this a roaming?
- Christmas greetings to kindergarten teachers
- How does Apple's mobile phone prevent SMS harassment?
- After breaking up, I wrote to my ex, which made my ex-boyfriend feel heartbroken.
- Harbin Ignite Public Examination Phone Number
- How to set the bell? I don't want money. I want a wife.
- What is the full version of the car greeting "The horn is ringing"?
- When the insurance company settles the claim, the account number for the claim settlement is wrong and has two wrong numbers. If the account number is mistyped, the money cannot be remitted, right? Bu
- My courier arrived and didn't have time to pick it up, and then sent a text message saying that it would be destroyed on the spot. Can the courier company do this?
- Zunyi college ranking