struts2 上传文件 File 为 Null 不走set方法

后缀改为了html<s:formaction="uploadimage.html"method="post"enctype="multipart/form-data"><... 后缀改为了html
<s:form action="uploadimage.html" method="post" enctype="multipart/form-data">
<s:file name="upFile"></s:file>
<s:submit label="上传" />
</s:form>

private File upFile;
private String upFileFileName;
private String upFileContentType;

public String execute() throws Exception {
String path = ServletActionContext.getServletContext().getRealPath("/uploadFile/");
BufferedInputStream bis = null;
BufferedOutputStream bos = null;

try{
File dir = new File(path);
if (!dir.exists()) {
dir.mkdirs();
}

bis = new BufferedInputStream(new FileInputStream(upFile));
bos = new BufferedOutputStream(new FileOutputStream(new File(dir,upFileFileName)));
byte[] buf = new byte[(int)upFile.length()];
int len = 0;
while(((len=bis.read(buf))!=-1)){
bos.write(buf, 0, len);
}
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(bos!=null){
bos.close();
}
if(bis!=null){
bis.close();
}
}catch(Exception e){
bos = null;
bis = null;
}
}

return SUCCESS;
}

public File getUpFile() {
return upFile;
}

public void setUpFile(File upFile) {
this.upFile = upFile;
}

public String getUpFileFileName() {
return upFileFileName;
}

public void setUpFileFileName(String upFileFileName) {
this.upFileFileName = upFileFileName;
}

public String getUpFileContentType() {
return upFileContentType;
}

public void setUpFileContentType(String upFileContentType) {
this.upFileContentType = upFileContentType;
}
展开
 我来答
67918334
2010-05-10 · TA获得超过726个赞
知道小有建树答主
回答量:839
采纳率:0%
帮助的人:591万
展开全部
给我winwsk@qq.com发个邮件。我传给你这个代码。我看你这个没看清楚
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
zhuzhu917
2010-05-10
知道答主
回答量:31
采纳率:0%
帮助的人:15.8万
展开全部
null 怎么set呢?
JS判断下嘛~
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
摆渡了没有
2010-05-11 · TA获得超过289个赞
知道答主
回答量:54
采纳率:0%
帮助的人:37.8万
展开全部
action="uploadimage.html"
---------------------------
你把action的后缀配置为html?
好好检查一下。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式