Javascript 如果我错了,我需要在同一个JSP中使用,并在Action类中为这个div设置消息?如果是,那么你能帮我吗?另外,请检查我的struts条目是否正确/index.jsp/index.jsp?您需要返回流结果类型,因为这里正在使用ajax。请检查我的更新答案
Javascript 如果我错了,我需要在同一个JSP中使用,并在Action类中为这个div设置消息?如果是,那么你能帮我吗?另外,请检查我的struts条目是否正确/index.jsp/index.jsp?您需要返回流结果类型,因为这里正在使用ajax。请检查我的更新答案 ,javascript,jquery,ajax,file-upload,struts2,Javascript,Jquery,Ajax,File Upload,Struts2,如果我错了,我需要在同一个JSP中使用,并在Action类中为这个div设置消息?如果是,那么你能帮我吗?另外,请检查我的struts条目是否正确/index.jsp/index.jsp?您需要返回流结果类型,因为这里正在使用ajax。请检查我的更新答案 <s:form action="fileUpload" method="post" enctype="multipart/form-data" > <s:file id="file" name="userImage" cssC
如果我错了,我需要在同一个JSP中使用,并在Action类中为这个div设置消息?如果是,那么你能帮我吗?另外,请检查我的struts条目是否正确
/index.jsp/index.jsp
?您需要返回流结果类型,因为这里正在使用ajax。请检查我的更新答案
<s:form action="fileUpload" method="post" enctype="multipart/form-data" >
<s:file id="file" name="userImage" cssClass="fileUpload" cssStyle="fileUpload" />
<button id="px-submit">Upload</button>
</s:form>
<script type="text/javascript">
jQuery(function($){
$('.fileUpload').fileUploader();
});
</script>
public class FileUploadAction extends ActionSupport{
private File userImage;
public File getUserImage() {
return userImage;
}
public void setUserImage(File userImage) {
this.userImage = userImage;
}
public String execute()
{
try
{
System.out.println("file name: " + userImage.toString());
}
catch(Exception e)
{
e.printStackTrace();
}
return SUCCESS;
}
<action name="commonDataImportAction_*" class="xxx.Action">
<result name="SUCCESS" type="stream">
<param name="contentType">text/html</param>
<param name="inputName">inputStream</param>
</result>
<button id="px-submit" type="submit">Upload</button>
<div id='message'>success message</div>
<form action="uploadImage" method="post" enctype="multipart/form-data">
<input type="file" name="image" class="fileUpload" multiple/>
<button id="px-submit" type="submit">Save all images</button>
<button id="px-clear" type="reset">Clear all</button>
</form>
$('.fileUpload').fileUploader({
autoUpload: false,
buttonUpload: '#px-submit',
buttonClear: '#px-clear',
});
public class UploadImageAction extends ActionSupport{
private File image;
private String imageContentType;
private String imageFileName;
//getter/setter for these
public String execute() {
String status="";
try{
//save file code here
status="<div id='message'>successfully uploaded</div>"; //on success
inputStream = new StringBufferInputStream(status);
}catch(WhateverException e){
status="<div id='status'>fail</div><div id='message'>Your fail message</div>"; //on error
inputStream = new StringBufferInputStream(status);
//other code
}
return SUCCESS;
}
private InputStream inputStream;
public InputStream getInputStream() {
return inputStream;
}
}
<action name="fileUpload" class="com.xxx.action.UploadImageAction">
<result type="stream">
<param name="contentType">text/html</param>
<param name="inputName">inputStream</param>
</result>
</action>