日期:2014-05-16 浏览次数:20726 次
<script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="jquery.form.js"></script> <s:form action="doUpload" method="post" enctype="multipart/form-data"> <s:file name="upload" label="File"/> <s:submit/> </s:form> <script type="text/javascript"> $('form').ajaxForm({ dataType: 'json', success: function(data) { /* do something you want */} }); </script>
package cream; import java.io.File; import com.opensymphony.xwork2.ActionSupport; public class UploadAction extends ActionSupport { private File file; private String contentType; private String filename; private String message; public void setUpload(File file) { this.file = file; } public void setUploadContentType(String contentType) { this.contentType = contentType; } public void setUploadFileName(String filename) { this.filename = filename; } public String execute() { //... return SUCCESS; } // getter with necessary public String getMessage() { return this.message; } }
<action name="doUpload" class="cream.UploadAction"> <result type="json"> <param name="wrapPrefix"><![CDATA[<textarea>]]></param> <param name="wrapSuffix"><![CDATA[</textarea>]]></param> <param name="contentType">text/html</param> </result> </action>