public class PhotoAction extends ActionSupport { //上传文件
private File[] image;
//上传文件名称
private String[] imageFileName;
//上传文件类型
private String[] imageContentType;
//房源编号
private int houseId;
private PhotoService photoService;
private HouseService houseService;//上传图片
public String add() throws IOException
{
//目录路径
String realpath=ServletActionContext.getServletContext().getRealPath("/images2");
if(image!=null)
{
//如果路径不存在,则创建路径
File savedir=new File(realpath);
if(!savedir.exists())savedir.mkdirs();
System.out.println("add");
//批量上传
for(int i=0;i<image.length;i++){
File savefile=new File(savedir,imageFileName[i]);
FileUtils.copyFile(image[i],savefile);
// Photo photo=new Photo();
// //封装房源ID
// photo.setHouse(houseService.findHouseById(houseId));
// //封装图片类型
// photo.setPhotoContent(imageContentType[i]);
// //封装图片名称
// photo.setPhotoName(imageFileName[i]);
// //封装图片路径
// photo.setPhotoPath(realpath);
// photoService.save(photo);
}
}
return SUCCESS;
}
Struts图片String类
private File[] image;
//上传文件名称
private String[] imageFileName;
//上传文件类型
private String[] imageContentType;
//房源编号
private int houseId;
private PhotoService photoService;
private HouseService houseService;//上传图片
public String add() throws IOException
{
//目录路径
String realpath=ServletActionContext.getServletContext().getRealPath("/images2");
if(image!=null)
{
//如果路径不存在,则创建路径
File savedir=new File(realpath);
if(!savedir.exists())savedir.mkdirs();
System.out.println("add");
//批量上传
for(int i=0;i<image.length;i++){
File savefile=new File(savedir,imageFileName[i]);
FileUtils.copyFile(image[i],savefile);
// Photo photo=new Photo();
// //封装房源ID
// photo.setHouse(houseService.findHouseById(houseId));
// //封装图片类型
// photo.setPhotoContent(imageContentType[i]);
// //封装图片名称
// photo.setPhotoName(imageFileName[i]);
// //封装图片路径
// photo.setPhotoPath(realpath);
// photoService.save(photo);
}
}
return SUCCESS;
}
Struts图片String类
type Status report
message No result defined for action action.PhotoAction and result input
description The requested resource (No result defined for action action.PhotoAction and result input) is not available.
但是,这个错误提示并没有反映真正的错误,求解?这个是addPhoto.jsp中主要代码:
<body>
<form action="photoAction_add_Success" method="post" enctype="multipart/form-data">
<input type="hidden" name="houseId" value="<%=request.getParameter("houseId") %>">
文件1:<input type="file" name="image"/></br>
文件2:<input type="file" name="image"/></br>
文件3:<input type="file" name="image"/></br>
文件4:<input type="file" name="image"/></br>
文件5:<input type="file" name="image"/></br>
<input type="submit" value="上传"/>
</form>
</body>
这个是PhotoAction.java主要代码:
public class PhotoAction extends ActionSupport { //上传文件
private File[] image;
//上传文件名称
private String[] imageFileName;
//上传文件类型
private String[] imageContentType;
//房源编号
private int houseId;
private PhotoService photoService;
private HouseService houseService;//上传图片
public String add() throws IOException
{
//目录路径
String realpath=ServletActionContext.getServletContext().getRealPath("/images2");
if(image!=null)
{
//如果路径不存在,则创建路径
File savedir=new File(realpath);
if(!savedir.exists())savedir.mkdirs();
System.out.println("add");
//批量上传
for(int i=0;i<image.length;i++){
File savefile=new File(savedir,imageFileName[i]);
FileUtils.copyFile(image[i],savefile);
// Photo photo=new Photo();
// //封装房源ID
// photo.setHouse(houseService.findHouseById(houseId));
// //封装图片类型
// photo.setPhotoContent(imageContentType[i]);
// //封装图片名称
// photo.setPhotoName(imageFileName[i]);
// //封装图片路径
// photo.setPhotoPath(realpath);
// photoService.save(photo);
}
}
return SUCCESS;
}
//setter和getter方法