对于这个问题相信大家都不陌生,应该都出过这样的错误,在网上也有很多帖子,但是都没有帮我解决我的这个问题。好了,直接进入主题,先谈下我的问题。
示例代码如下:
Struts.xml中action代码代码
<action name="upload" class="com.test.action.UploadAction">
<result name="success">/uploadsuccess.jsp</result>
</action>
Upload.jsp中关键代码代码
<s:form action="upload" enctype="multipart/form-data" method="post">
<s:file name="file"></s:file>
<s:submit value="submit"></s:submit>
</s:form>
Uploadaction中的execute()方法代码
public String execute() throws Exception
{
InputStream is = new FileInputStream(file);
OutputStream os = new FileOutputStream("e:\\" + fileFileName);
byte[] buffer = new byte[1024];
int length = 0;
while (-1 != (length = is.read(buffer)))
{
os.write(buffer,0,length);
}
os.close();
is.close();
return "success";
}
从错误提示看很明显是Action中result配置不对。但是就是不知道哪儿错了。
PS:补充一下,我把struts.xml和UploadAction.jsp表单中的action都换个名字,比如说fileupload,然后就没有错了,可以实现上传了。
示例代码如下:
Struts.xml中action代码代码
<action name="upload" class="com.test.action.UploadAction">
<result name="success">/uploadsuccess.jsp</result>
</action>
Upload.jsp中关键代码代码
<s:form action="upload" enctype="multipart/form-data" method="post">
<s:file name="file"></s:file>
<s:submit value="submit"></s:submit>
</s:form>
Uploadaction中的execute()方法代码
public String execute() throws Exception
{
InputStream is = new FileInputStream(file);
OutputStream os = new FileOutputStream("e:\\" + fileFileName);
byte[] buffer = new byte[1024];
int length = 0;
while (-1 != (length = is.read(buffer)))
{
os.write(buffer,0,length);
}
os.close();
is.close();
return "success";
}
从错误提示看很明显是Action中result配置不对。但是就是不知道哪儿错了。
PS:补充一下,我把struts.xml和UploadAction.jsp表单中的action都换个名字,比如说fileupload,然后就没有错了,可以实现上传了。
解决方案 »
- websphere6.1 com.ibm.ws.jsp.JspCoreException JSPG0055E
- java 项目经理 or 架构 求职
- spring
- <iframe>问题
- 关于多对一关联的问题 Exception in thread "main" org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
- 请教:Hibernate与中文字段名
- hibernate 中id generator 问题,望解答!
- 一个hibernate 实例运行,为什么老是报NullPointerException?
- 数据库字段为空的情况下Hibernate的读取异常?
- 怎麽樣用jsp做RMI調用的客戶端
- 问一个问题关于 struts2返回结果的
- 如何根据数据表数据和CSV文件中内容生成CSV文件?
配置action的时候我们一般把method="" 这个属性写上,就算是execute()方法,也写上