request.getSession().getServletContext().getRealPath("/");想取到项目路径,结果报空指针
大神们请解答下小弟的疑问吧~~
public String execute() throws Exception { java.io.InputStream is = new java.io.FileInputStream(upload); java.io.OutputStream os = new java.io.FileOutputStream(ServletActionContext .getServletContext().getRealPath( "/UploadImages" ) + "/" + uploadFileName); //"d://upload//"+ uploadFileName); String s2=httpservletrequest.getSession().getServletContext().getRealPath("/"); System.out.println(s2); byte buffer[] = new byte[8192]; int count = 0; while ((count = is.read(buffer)) > 0) { os.write(buffer, 0, count); } os.close(); is.close();// String s1=ServletActionContext.getServletContext().getRealPath("/");// String s2=httpservletrequest.getSession().getServletContext().getRealPath("/") ;// System.out.println(s2); return SUCCESS; }