对于这个问题相信大家都不陌生,应该都出过这样的错误,在网上也有很多帖子,但是都没有帮我解决我的这个问题。好了,直接进入主题,先谈下我的问题。
   示例代码如下:
 
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,然后就没有错了,可以实现上传了。

解决方案 »

  1.   

    upload是关键字?有这么一说吗?struts1都忘记了。或者在struts.xml里面upload没有重复定义吧?
      

  2.   

     问题我就不讲了。讲讲思路:你应该学会对一个问题就行分断来处理,先找出具体问题所在。1。首先你在action里设断点了没有?  你看有没有跑进去?  如果没有跑进去,那说明问题出在那里???2。如果跑进后台了,但是回不到页面,那问题又出在那里?3。习惯上我们一般很少使用execute()这个方法
        配置action的时候我们一般把method="" 这个属性写上,就算是execute()方法,也写上
      

  3.   

    好像是这样的 所以命名要规范 action的命名应该和具体业务相关