String pathdir = "/uploadfile/article";
//2.得到保存目录的真实路径
String realpathdir = request.getSession().getServletContext().getRealPath(pathdir);
System.out.println(realpathdir);
打印处理的是
D:\Lomboz\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\htrproject\uploadfile\article\
上传的文件跑到workplace里去了我用的lomboz 请教.不胜感激好像是要到web.xml文件中配置吧.
在web.xml中怎么配置.
教教小弟啊
//2.得到保存目录的真实路径
String realpathdir = request.getSession().getServletContext().getRealPath(pathdir);
System.out.println(realpathdir);
打印处理的是
D:\Lomboz\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\htrproject\uploadfile\article\
上传的文件跑到workplace里去了我用的lomboz 请教.不胜感激好像是要到web.xml文件中配置吧.
在web.xml中怎么配置.
教教小弟啊
GoddsForm goodsForm = (GoddsForm) form;//这是一个form表单里面有一个字段为上传文件的路径 用FormFile 保存
FormFile pic = goodsForm.getFilePic();
String fileName = pic.getFileName();
FileOutputStream fos;
String path = this.getServlet().getServletContext().getRealPath("/");
try {
fos = new FileOutputStream(path + "upgoods\\" + userID + fileName);
fos.write(pic.getFileData());
fos.flush();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
String filepath = request.getSession().getServletContext().getRealPath("/")+"myfiles"; "myfiles"可变,为自己设置的存放文件的目录.
自己设置个环境变量,System.getenv("FILEPATH")获取路径;
然后把你的文件保存到这个目录就好了!
/servers/tomcat v6.0 server at localhost server
但是上传的文件目录还是没有变啊..Server Location 没有这个东东
解决了那个长路径问题了.谢谢大家