struts2上传问题!!急。急

yatming66 2011-03-18 10:01:25
------------------------------页面--------------------
<s:form action="/entuser/entUserAction_uploadImage.do"
method="POST" enctype="multipart/form-data" >
<s:file name ="uploadImage" label ="uploadImage" />
<s:submit />
</s:form >
-----------------------------Action有set get 方法--------------------------------
private File uploadImage;
private String uploadImageFileName;

System.out.println("uploadImage()!");
System.out.println(uploadImageFileName);
System.out.println(uploadImage);
String realpath = ServletActionContext.getServletContext().getRealPath("/uploadimage");
System.out.println(realpath+"----");
File file=new File (new File(realpath), uploadImageFileName);
System.out.println(file+"||||||||||||||");
if(!file.getParentFile().exists()){
file.getParentFile().mkdirs();
}
FileUtils.copyFile(uploadImage, file);
---------------------------action.xml--------------
<package name="entuser" extends="default" namespace="/entuser">
<action name="entUserAction_*" class="com.efreen.entuser.action.EntUserAcion" method="{1}">
<result name="success">/action.jsp</result>
<result name="forword">/forword.jsp</result>
</action>
</package>
-----------------------------------
注:可以进到action,就是在action中得不到文件和文件名!好像就跟没有提交一样
控制台报空指针异常!
麻烦帮看看
-------------------------------------
...全文
68 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
redlotus_lyn 2011-03-21
  • 打赏
  • 举报
回复
应该是配置有问题

commons-fileupload.jar
commons-io.jar

以上两个jar引用了?
jijihahalala 2011-03-20
  • 打赏
  • 举报
回复
表单中的namespace和action应该分开写,源码上有说明。
yatming66 2011-03-18
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 hzw2312 的回复:]
Java code

String realpath = ServletActionContext.getServletContext().getRealPath("/uploadimage");


这玩意你上那取的?
[/Quote]

这是取得存储的路径而已 没有问题
private File uploadImage;
private String uploadImageFileName;
现在是这2个参数根本为null。不知道怎么回事了。
BUG胡汉三 2011-03-18
  • 打赏
  • 举报
回复

String realpath = ServletActionContext.getServletContext().getRealPath("/uploadimage");

这玩意你上那取的?

67,515

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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