在执行上传时,上传成功后无法跳转的成功页面
struts.xml文件:
<?xml version="1.0" encoding="GBK" ?> 
  <!DOCTYPE struts (View Source for full doctype...)> 
<struts>
  <constant name="struts.i18n.encoding" value="gb2312" /> 
  <package name="pack_upload" extends="struts-default">
    <action name="upload" class="action.Upload">
      <result name="success">/success.jsp</result> 
      <result name="error">/error.jsp</result> 
   </action>
  </package>
</struts>
action代码如下:
public class Upload extends ActionSupport {
private File file;
private String fileName;
private String imageFileName; public File getFile() {
return file;
} public void setFile(File file) {
this.file = file;
} public String getFileName() {
return fileName;
} public void setFileName(String fileName) {
this.fileName = fileName;
}
public String execute() {
this.imageFileName = (new Date().getDate())
+ fileName.substring(this.fileName.indexOf("."));
File imageFile = new File(ServletActionContext.getServletContext()
.getRealPath("")
+ "/" + this.imageFileName);
try {
InputStream in=null;
OutputStream out=null;
try {
in= new BufferedInputStream(new FileInputStream(file),1024);
out =new BufferedOutputStream(new FileOutputStream(imageFile),1024);
byte[] bytes=new byte[1024];
while(in.read(bytes)>0){
out.write(bytes);
}
in.close();
out.close();
} catch (FileNotFoundException e) {
System.out.println("找不到文件");
throw e;
}catch(IOException e){
System.out.println("文件写入或者读取错误");
throw e;
}
} catch (Exception e) {
e.printStackTrace();
return "error";
// TODO: handle exception
}
return super.SUCCESS;
}
}
页面代码如下:
上传页面:
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
  </head>
  
  <body>
    <s:form action="upload" enctype="multipart/form-data" method="post">
     <s:file name="file" />
     <s:textfield name="fileName"></s:textfield>
     <s:submit/>
    </s:form>
  </body>
</html>成功页面:
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'success.jsp' starting page</title>
    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->  </head>
  
  <body>
    <img src='<s:property value ="imageFileName" />'/>
  </body>
</html>注:上传能够成功,就是在跳转到成功页面时出错显示 no result found for action action.Upload result success