Struts2附件上传,action接收的值为null

jiyingt036 2009-04-23 02:17:35
upload.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>上传附件</title>
</head>

<body>
<form action="upload.action" method="post" enctype="multipart/form-data" >
标题:<input type="text" name="title" value=""><br><br><br><br>
<input type="file" name="file"><br>
<input type="file" name="file"><br>
<input type="file" name="file"><br>
<input type="submit" value="上传"/>
</form>
</body>
</html>

UploadAction.java

public class UploadAction extends ActionSupport {
private String title;
private File[] file;
private String[] fileContentType;
private String[] fileFileName;

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public File[] getFile() {
return file;
}

public void setFile(File[] file) {
this.file = file;
}

public String[] getFileContentType() {
return fileContentType;
}

public void setFileContentType(String[] fileContentType) {
this.fileContentType = fileContentType;
}

public String[] getFileFileName() {
return fileFileName;
}

public void setFileFileName(String[] fileFileName) {
this.fileFileName = fileFileName;
}



public String upload(){
System.out.println(title);
System.out.println(file);
return SUCCESS;
}


}


struts-upload.xml

<struts>
<package name="/upload" namespace="/custom/market/customer" extends="base">
<action name="upload" class="custom.market.customer.UploadAction" method="upload">
<interceptor-ref name="fileUpload"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
<result name="success">/upload.jsp</result>
</action>
</package>

</struts>

...全文
689 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiyingt036 2009-04-24
  • 打赏
  • 举报
回复
是这样的,以前有一个对附件的filter了,我这个模块是后面加入的(用struts2.0),我怎样不动以前的过滤器,
9441 2009-04-23
  • 打赏
  • 举报
回复
你的拦截器配置的对不对?你可以参考struts-default.xml中的配置
zidasine 2009-04-23
  • 打赏
  • 举报
回复
加个<result type="input" >然后看看是什么错误导致的 是文件过大 还是什么
toss2000 2009-04-23
  • 打赏
  • 举报
回复
把上传文件改为
<form action="/custom/market/customer/upload.action" method="post" enctype="multipart/form-data" >
试试
Epiphone 2009-04-23
  • 打赏
  • 举报
回复
http://www.duduwolf.com/wiki/2007/334.html 看看这个 写的很详细了 Struts2上传
jiyingt036 2009-04-23
  • 打赏
  • 举报
回复
title和file都为null值,是不是还要配置什么?(刚接触struts2,不要见笑)

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧