【发布时间】:2014-05-21 09:54:45
【问题描述】:
我尝试使用 Struts2 上传文件(图像)。但是,我的文件、文件内容和文件名类型有一个空值! 我尝试搜索此问题,但没有任何结果。
这就是我想要做的:
jsp:
<s:form id="registerSubmit" method="post" enctype="multipart/form-data" theme="bootstrap">
<s:textfield name="tel" cssClass="form-control" label="tel :"></s:textfield>
<label for="myFile">Upload your file</label>
<input type="file" name="file" />
<button type="submit" id="submit" > Enregistrer</button>
</s:form>
行动:
public class Gestion extends ActionSupport implements SessionAware, ModelDriven{
private Visit c;
private Service Service;
private Long tel;
private File file;
private String fileContentType;
private String fileFileName;
public String addvisit(){
c = new visit();
Service = new ServiceImpl();
c.setTel(tel);
System.out.println(fileContentType); //null
System.out.println(fileFileName); //null
byte[] bFile = null;
if(file != null)
bFile = new byte[(int) file.length()];
c.setPhoto(bFile); // null
Service.add(c);
return "success";
}
//setters and getters
}
struts.xml
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.multipart.maxSize" value="10000000" />
<package name="login" extends="struts-default" namespace="/">
<action name="addvisit" class="action.Gestion"
method="addvisit">
<interceptor-ref name="fileUpload">
<param name="maximumSize">2097152</param>
<param name="allowedTypes">
image/png,image/gif,image/jpeg,image/pjpeg
</param>
</interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
<result name="success" type="json" >
<param name="root">map</param>
</result>
</action>
</package>
</struts>
【问题讨论】:
-
感谢 Roman,我添加了 jars(commons fileupload 和 commons io)而不是“Deployment Assembly”,但我仍然有一个空值!
-
您可能没有读到最佳答案。
-
最佳答案是什么?
-
我删除了
并添加了 ,但没有任何结果,请罗马先生帮忙!跨度>
标签: jsp twitter-bootstrap struts2 upload interceptor