Ajax asynchronous upload _ajax in jquery related

Source: Internet
Author: User
Tags constant file upload id3

Looking for a long time finally found on the Internet Ajax asynchronous upload file method, but most of the internet is PHP, I changed to struts2 write the same, I hope to learn Java people have some help. I uploaded the music file.

Ajaxfileupload.js This JS file is the main file, be sure to import.

JSP page, where I also made a div of the hidden *****************************

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%> <% String Path = Request.getcontextpath ()
;
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/"; %> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >  

Action upload background code *************************************

Package action;
Import Java.io.File;
Import java.io.IOException;
Import Java.io.OutputStream;
Import Org.apache.commons.io.FileUtils;
Import Org.apache.struts2.json.annotations.JSON;
Import Org.farng.mp3.MP3File;
Import org.farng.mp3.TagException;
Import Org.farng.mp3.id3.AbstractID3v2;
Import Org.farng.mp3.id3.ID3v1;
Import ORG.FARNG.MP3.LYRICS3.ABSTRACTLYRICS3;
Import com.base.BaseAction;
Import Com.opensymphony.xwork2.ActionSupport; public class Upload extends Baseaction {private static final long serialversionuid = -4848248679889814408l; private Strin
G FileName;
Private File upload; Public File Getupload () {return upload.} public void Setupload (File upload) {this.upload = upload;} public void SE Tuploadfilename (String fileName) {this.filename = filename;}/* * Song upload upload operation/public void Uploadaction () throws IOE xception {System.out.println ("entered the way!")
    ");
    String targetdirectory = "D:\\upload";
    System.out.println (upload); File target = new file (targetdirectorY, FileName);
    Fileutils.copyfile (upload, target);
     String path = targetdirectory+ "\" +filename; 
        try {mp3file file = new Mp3file (path);//1,lyrics abstractid3v2 ID3v2 = File.getid3v2tag (); 
        ID3v1 ID3v1 = File.getid3v1tag ();
        String ss = ""; 
            if (ID3v2!= null) {System.out.println ("ID3v2"); SS = Id3v2.getalbumtitle () + ";" +id3v2.getsongtitle () + ";"
            +id3v2.getleadartist ();
            String str = "{' msg ', '" +ss+ "'}";
            String str = SS;
          OutPut (str); System.out.println (Id3v2.getalbumtitle ());//Album Name System.out.println (Id3v2.getsongtitle ());//Song name Syste 
          M.out.println (Id3v2.getleadartist ());//singer} else {System.out.println ("ID3v1"); 
          System.out.println (Id3v1.getalbumtitle ()); 
          System.out.println (Id3v1.getsongtitle ()); 
        System.out.println (Id3v1.getleadartist ()); } ABSTRACTLYRICS3 Lrc3tag = File.getlyricS3tag (); 
          if (Lrc3tag!= null) {String lyrics = Lrc3tag.getsonglyric (); 
        System.out.println (lyrics); 
      } catch (IOException e) {e.printstacktrace (); 
      catch (Tagexception e) {e.printstacktrace (); 
 } System.out.println ("over"); }
}

Struts.xml configuration file *********************************

<?xml version= "1.0" encoding= "UTF-8"?> <!
DOCTYPE struts public
  "-//apache Software foundation//dtd struts Configuration 2.0//en"
  "http:// Struts.apache.org/dtds/struts-2.0.dtd ">
<struts>
  <constant name=" struts.i18n.encoding "value = "UTF-8"/>
    //Set upload file maximum
    <constant name= "struts.multipart.maxSize" value= "10485760"/>
  
  < Package name= "Upload namespace="/"extends=" Struts-default "> <action name=" uploadaction "class="
     action. Upload "method=" uploadaction ">
       <result name=" Success ">/index.jsp</result>
      
     </action >
  </package>
</struts>

Later, after debugging, found that Firefox and IE incompatibility caused no execution to fight for results, so I uploaded ajaxfileupload.js I modified the source code

The above is the article to introduce jquery Ajax asynchronous upload, I hope to help.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.