日期:2014-05-17 浏览次数:20748 次
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Insert title here</title> <script src="scripts/jquery-1.4.2.js"></script> <script src="scripts/ajaxfileupload.js"></script> <script type="text/javascript"> function uploadFile(){ $('#fileUpload').click(); $.ajaxFileUpload({ url: "ajax/fileUpload.action", //data: {"fileRemak":"123"} , //$("#MyForm").serialize(), secureuri:false, fileElementId:'fileUpload', dataType: 'json', //type : "post" , success: function (msg) { alert("上传附件成功! "+msg); $('#fileUpload').val() ; //$('#fileUpload').val(''); }, error: function () { alert("异常,上传失败!"); //$('#fileUpload').val(''); } }); } </script> </head> <body > <table align="center" border="1" cellpadding="0" cellspacing="1" class="formTableCore"> <tr> <td class="formLabel" colspan="3"> <span id="b6"> <input type="file" id="fileUpload" name="fileUpload" style="display:none;" /> <input type="button" value="新增附件" class="formButton" onclick="uploadFile();"/> </span> </td> </tr> </table> </body> </html>
package ajax; import java.io.File; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.http.HttpServletResponse; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionSupport; public class FileUpload{ public String fileRemak ; public File fileUpload ; public File getFileUpload() { return fileUpload; } public void setFileUpload(File fileUpload) { this.fileUpload = fileUpload; } public String getFileRemak() { return fileRemak; } public void setFileRemak(String fileRemak) { this.fileRemak = fileRemak; } public String fileUpload(){ File copyFile = fileUpload ; System.err.println("================================="); System.err.println("================================="); System.err.println("================================="); System.err.println("================================="); System.out.println("================================="); System.out.println("