java 实例化list_List对象不能实例化是为什么?

今天在学习文件上传,但是在批量上传包含图片的文件时,程序报错。

package com.control;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.util.ArrayList;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.bean.Student;

import com.daoImpl.StuManagerDaoImpl;

import com.opensymphony.xwork2.ActionSupport;

public class AddAllStuAction extends ActionSupport{

private List image;

private List imageFileName;

private List imageContentType;

//重写父类的execute方法

public String execute(){

StuManagerDaoImpl dao=new StuManagerDaoImpl();

HttpServletRequest request=ServletActionContext.getRequest();

//因为批量添加传过来的信息很多,所有需要定义一个数组进行接收

String [] sid=request.getParameterValues("sid");

String [] sname=request.getParameterValues("sname");

String [] sage=request.getParameterValues("sage");

//得到上传路径

String path=ServletActionContext.getServletContext().getRealPath("/stuImage");

System.out.println(path);

for(int i=0;i

//设置目标路径

File file=new File(path,imageFileName.get(i));

try {

//文件拷贝

FileInputStream fis=new FileInputStream(image.get(i));

FileOutputStream fos=new FileOutputStream(file);

//定义一个数组

byte [] b=new byte[1024];

int len;

while((len=fis.read(b))>0){

fos.write(b,0, len);

}

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

//现在实例化学生对象

Student stu=new Student();

stu.setSid(Integer.parseInt(sid[i]));

stu.setSname(sname[i]);

stu.setSage(Integer.parseInt(sage[i]));

stu.setSphoto("stuimage"+"\\"+imageFileName.get(i));

dao.toSaveStu(stu);

}

return SUCCESS;

}

public List getImage() {

return image;

}

public void setImage(List image) {

this.image = image;

}

public List getImageFileName() {

return imageFileName;

}

public void setImageFileName(List imageFileName) {

this.imageFileName = imageFileName;

}

public List getImageContentType() {

return imageContentType;

}

public void setImageContentType(List imageContentType) {

this.imageContentType = imageContentType;

}

}

浏览器访问的时候,点击提交,报空指针异常。哪位大神可以指导下我啊?跪求

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值