我在写一个用JSP对EXCEL文件操作的程序,根据网上前辈的指点,小有成果,
不过现在有个问题是,该文件我只能用绝对路径访问,程序片段如下:
InputStream is = new FileInputStream("E:/lx/kq.xls");
在这里参数为("E:/lx/kq.xls"),也就是我必须把文件放在E盘下面的名称
为lx的文件夹里面才能访问得到,而我现在想要的是文件随便放在我的电脑的
甚么地方也能访问得到,不知道该如何实现。望哪个高手指点迷津,不胜感激!
不过现在有个问题是,该文件我只能用绝对路径访问,程序片段如下:
InputStream is = new FileInputStream("E:/lx/kq.xls");
在这里参数为("E:/lx/kq.xls"),也就是我必须把文件放在E盘下面的名称
为lx的文件夹里面才能访问得到,而我现在想要的是文件随便放在我的电脑的
甚么地方也能访问得到,不知道该如何实现。望哪个高手指点迷津,不胜感激!
InputStream is = new FileInputStream(file);
InputStream fi = this.getClass().getResourceAsStream( "/ "+kq.xls); //路径自己配置
<input name='file1' type= "file ">actionform:
public class FileUpLoadActionForm
extends ActionForm {
public FileUpLoadActionForm() {
} private FormFile file1;
public ActionErrors validate(ActionMapping actionMapping,
HttpServletRequest httpServletRequest) {
/**@todo: finish this method, this is just the skeleton.*/
return null;
} public void reset(ActionMapping actionMapping,
HttpServletRequest httpServletRequest) { } public FormFile getFile1() {
return file1;
}
public void setFile1(FormFile file1) {
this.file1 = file1;
}} action:public ActionForward upload(ActionMapping actionMapping,
ActionForm actionForm, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws Exception {
FileUpLoadActionForm fileForm = (FileUpLoadActionForm) actionForm;fileForm.getFile1();
//实现你的代码
}