大家好我在学习struts2上传文件的时候为什么会出现这种错误
typeStatusreportmessage/struts2/test/hello_execute.actiondescriptionTherequestedresou...
type Status report
message /struts2/test/hello_execute.action
description The requested resource (/struts2/test/hello_execute.action) is not available.
我的action种是这样写得:
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionContext;
public class HelloWorld {
public File image;
public String imageFilename;
public File getImage() {
return image;
}
public void setImage(File image) {
this.image = image;
}
public String getImageFilename() {
return imageFilename;
}
public void setImageFilename(String imageFilename) {
this.imageFilename = imageFilename;
}
public String execute() throws Exception{
String realpath=ServletActionContext.getServletContext().getRealPath("/images");//通过这个获得长传得绝对路径
System.out.println(realpath);
if(image!=null){
File savepath=new File(new File(realpath),imageFilename);
if(!savepath.getParentFile().exists())savepath.mkdirs();
FileUtils.copyFile(image, savepath);
ActionContext.getContext().put("message", "上传成功");
}
return "success";
}
}
我的struts2.xml是这样写得
<constant name="struts.action.extension" value="action"/>
<package name="itcast" namespace="/test" extends="struts-default">
<action name="hello_*" class="itcast.HelloWorld" method="{1}">
<result name="success" >/WEB-INF/page/MyJsp.jsp</result></action>
页面上传是这么写的:
<body>
<form action="${pageContext.request.contextPath}/test/hello_execute.action" enctype="multipart/form-data" method="post">
文件:<input type="file" name="image"><br>
<input type="submit" value="上传"><br>
</form>
</body>
导入包了也,但是为什么会出现问题,哪位高手帮帮忙
谢谢了。 展开
message /struts2/test/hello_execute.action
description The requested resource (/struts2/test/hello_execute.action) is not available.
我的action种是这样写得:
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionContext;
public class HelloWorld {
public File image;
public String imageFilename;
public File getImage() {
return image;
}
public void setImage(File image) {
this.image = image;
}
public String getImageFilename() {
return imageFilename;
}
public void setImageFilename(String imageFilename) {
this.imageFilename = imageFilename;
}
public String execute() throws Exception{
String realpath=ServletActionContext.getServletContext().getRealPath("/images");//通过这个获得长传得绝对路径
System.out.println(realpath);
if(image!=null){
File savepath=new File(new File(realpath),imageFilename);
if(!savepath.getParentFile().exists())savepath.mkdirs();
FileUtils.copyFile(image, savepath);
ActionContext.getContext().put("message", "上传成功");
}
return "success";
}
}
我的struts2.xml是这样写得
<constant name="struts.action.extension" value="action"/>
<package name="itcast" namespace="/test" extends="struts-default">
<action name="hello_*" class="itcast.HelloWorld" method="{1}">
<result name="success" >/WEB-INF/page/MyJsp.jsp</result></action>
页面上传是这么写的:
<body>
<form action="${pageContext.request.contextPath}/test/hello_execute.action" enctype="multipart/form-data" method="post">
文件:<input type="file" name="image"><br>
<input type="submit" value="上传"><br>
</form>
</body>
导入包了也,但是为什么会出现问题,哪位高手帮帮忙
谢谢了。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询