运行后报错提示如下:
Could not find action or result
There is no Action mapped for action name upload/. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:178)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:861)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1584)
at java.lang.Thread.run(Unknown Source)
跪求高手指教。项目文件如下:1.UploadAction.java package lee;import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;
import java.io.File;
import java.io.*;
public class UploadAction extends ActionSupport {
private String title;
private File upload;
private String uploadContentType; //这两个属性是必须有的,有框架要用
private String uploadFileName; //这两个属性是必须有的,有框架要用 //接受依赖注入的属性
private String savePath; public String getTitle() {
return title;
} public void setTitle(String title) {
this.title = title;
} public File getUpload() {
return upload;
} public void setUpload(File upload) {
this.upload = upload;
} public String getUploadContentType() {
return uploadContentType;
} public void setUploadContentType(String uploadContentType) {
this.uploadContentType = uploadContentType;
} public String getUploadFileName() {
return uploadFileName;
} public void setUploadFileName(String uploadFileName) {
this.uploadFileName = uploadFileName;
} public String getSavePath() {
return ServletActionContext.getRequest().getRealPath(savePath);
}
//接受依赖注入的方法
public void setSavePath(String savePath) {
this.savePath = savePath;
}
public String execute()throws Exception{
System.out.println("开始上传单个文件-------------");
System.out.println(this.getSavePath());
System.out.println("=========="+this.getUploadFileName());
System.out.println("=========="+this.getUploadContentType());
System.out.println("=========="+this.getUpload());
//以服务器的文件保存地址和原文件名建立上传文件输出流
FileOutputStream fos=new FileOutputStream(this.getSavePath()+"\\"+this.getUploadFileName());
FileInputStream fis=new FileInputStream(this.getUpload());
byte[] buffer=new byte[1024];
int len=0;
while((len=fis.read(buffer))>0){
fos.write(buffer,0,len);
}
return SUCCESS;
}
} 2.struts.xml <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts> <constant name="struts.custom.i18n.resources" value="globalMessages"/>
<constant name="struts.i18n.encoding" value="GBK"/> <package name="lee" extends="struts-default">
<action name="upload" class="lee.UploadAction">
<param name="savePath">/upload</param>
<result>/succ.jsp</result>
</action>
</package>
</struts> 3.web.xml <?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<!-- 定义Struts2的FilterDispathcer的Filter -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter> <!-- FilterDispatcher用来初始化struts2并且处理所有的WEB请求。 -->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app> 4.upload.html <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
<title>简单的文件上传</title>
</head>
<body>
<form action="upload.action" method="post" enctype="multipart/form-data">
文件标题:<input type="text" name="title" /><br>
选择文件:<input type="file" name="upload" /><br>
<input value="上传" type="submit" />
</form>
</body> 5.succ.jsp <%@ page language="java" contentType="text/html;charset=GBK"%>
<%@taglib prefix="s" uri="/struts-tags"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>上传成功!</title>
</head>
<body>
上传成功!<br>
文件标题:<s:property value="+ title"/>
文件为:<img src="<s:property value="'upload/' + uploadFileName"/>"/><br>
</body>
</html></html>
Could not find action or result
There is no Action mapped for action name upload/. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:178)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:861)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1584)
at java.lang.Thread.run(Unknown Source)
跪求高手指教。项目文件如下:1.UploadAction.java package lee;import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;
import java.io.File;
import java.io.*;
public class UploadAction extends ActionSupport {
private String title;
private File upload;
private String uploadContentType; //这两个属性是必须有的,有框架要用
private String uploadFileName; //这两个属性是必须有的,有框架要用 //接受依赖注入的属性
private String savePath; public String getTitle() {
return title;
} public void setTitle(String title) {
this.title = title;
} public File getUpload() {
return upload;
} public void setUpload(File upload) {
this.upload = upload;
} public String getUploadContentType() {
return uploadContentType;
} public void setUploadContentType(String uploadContentType) {
this.uploadContentType = uploadContentType;
} public String getUploadFileName() {
return uploadFileName;
} public void setUploadFileName(String uploadFileName) {
this.uploadFileName = uploadFileName;
} public String getSavePath() {
return ServletActionContext.getRequest().getRealPath(savePath);
}
//接受依赖注入的方法
public void setSavePath(String savePath) {
this.savePath = savePath;
}
public String execute()throws Exception{
System.out.println("开始上传单个文件-------------");
System.out.println(this.getSavePath());
System.out.println("=========="+this.getUploadFileName());
System.out.println("=========="+this.getUploadContentType());
System.out.println("=========="+this.getUpload());
//以服务器的文件保存地址和原文件名建立上传文件输出流
FileOutputStream fos=new FileOutputStream(this.getSavePath()+"\\"+this.getUploadFileName());
FileInputStream fis=new FileInputStream(this.getUpload());
byte[] buffer=new byte[1024];
int len=0;
while((len=fis.read(buffer))>0){
fos.write(buffer,0,len);
}
return SUCCESS;
}
} 2.struts.xml <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts> <constant name="struts.custom.i18n.resources" value="globalMessages"/>
<constant name="struts.i18n.encoding" value="GBK"/> <package name="lee" extends="struts-default">
<action name="upload" class="lee.UploadAction">
<param name="savePath">/upload</param>
<result>/succ.jsp</result>
</action>
</package>
</struts> 3.web.xml <?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<!-- 定义Struts2的FilterDispathcer的Filter -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter> <!-- FilterDispatcher用来初始化struts2并且处理所有的WEB请求。 -->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app> 4.upload.html <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
<title>简单的文件上传</title>
</head>
<body>
<form action="upload.action" method="post" enctype="multipart/form-data">
文件标题:<input type="text" name="title" /><br>
选择文件:<input type="file" name="upload" /><br>
<input value="上传" type="submit" />
</form>
</body> 5.succ.jsp <%@ page language="java" contentType="text/html;charset=GBK"%>
<%@taglib prefix="s" uri="/struts-tags"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>上传成功!</title>
</head>
<body>
上传成功!<br>
文件标题:<s:property value="+ title"/>
文件为:<img src="<s:property value="'upload/' + uploadFileName"/>"/><br>
</body>
</html></html>
解决方案 »
- xfire发布服务,如何控制WSDL文件中的参数
- 我想通过选中复选框 ,然后点击删除,实现删除功能,这个参数怎么传递啊
- 一个javascript问题
- hibernate + struts 问题
- 帮忙介绍一本比较好的开发jsp自定义标签的书
- NHibernate 现在能连接sql2008么
- 请教!!!在哪能下到Swing系列的源代码??谢谢!!~~~
- java中的socket传文件的问题
- How to connect eclipse cvs depository by Eclipse 2.1?
- json 对象post 请求怎样写类型转换器才能注入到struts 的List<Object>中
- 各位大哥大姐帮忙,在哪可以下载flex电子书
- flex
返回的success没有对应的配置
<param name="savePath">/upload</param>
<result>/succ.jsp</result>
</action>
在这里作为参数传到UploadAction里面的啊。。
private String uploadFileName;
private String uploadContentType;
private String fileUplodPath;
//鉴定允许上传文件的类型
private String allowedTypes;
/**
* 执行文件上传方法
* @return
* @throws IOException
*/
public String upFile() throws IOException
{
String toFaroward=null;
//分割允许上传文件的格式成数组
String[] alTy=getAllowedTypes().split(",");
//获取上传文件的格式
String isType=getUploadContentType();
//判断格式是否被允许上传
for (int i = 0; i < alTy.length; i++) {
if (alTy[i].equals(isType)) {
//判断文件的大小
if (getUpload().length()<=BUFFER_SIZE) {
//根据服务器的文件保存地址和原文件名创建目录文件全路径
setFileUplodPath("/filePath");
String dstPathString=ServletActionContext.getServletContext().getRealPath(getFileUplodPath())+"\\"+getUploadFileName();
//System.out.println("filepath"+dstPathString);
String filescr=ServletActionContext.getRequest().getContextPath()+
getFileUplodPath()+"/"+getUploadFileName();
File dstFile=new File(dstPathString);
try {
//此两个方法均可用,
//copyFile(getUpload(), dstFile);
//apache封装的方法.
FileUtils.copyFile(getUpload(), dstFile);
ServletActionContext.getRequest().setAttribute("srcpath", filescr);
toFaroward="SUCCESS";
} catch (Exception e) {
toFaroward="eorr";
}
}else {
ServletActionContext.getRequest().setAttribute("eorrs", "文件太大了!");
toFaroward="eorr";
}
}else {
ServletActionContext.getRequest().setAttribute("eorrs", "文件类型不正确");
ServletActionContext.getRequest().setAttribute("alTYPES", alTy);
toFaroward="eorr";
}
}
return toFaroward;
}
public File getUpload() {
return upload;
} public void setUpload(File upload) {
this.upload = upload;
} public String getUploadFileName() {
return uploadFileName;
} public void setUploadFileName(String uploadFileName) {
this.uploadFileName = uploadFileName;
} public String getUploadContentType() {
return uploadContentType;
} public void setUploadContentType(String uploadContentType) {
this.uploadContentType = uploadContentType;
} public String getFileUplodPath() {
return fileUplodPath;
} public void setFileUplodPath(String fileUplodPath) {
this.fileUplodPath = fileUplodPath;
} public String getAllowedTypes() {
return allowedTypes;
} public void setAllowedTypes(String allowedTypes) {
this.allowedTypes = allowedTypes;
}
可以参考这个
楼主可以把这个给删了,可能就不会报错了