`

有關getRealPath()相關問題

阅读更多
翻一下 api doc http://java.sun.com/j2ee/1.4/docs/api/index.html
你會發現到 request.getRealPath( ) 這個方法己經 Deprecated
現在都會使用 ServletContext.getRealPath(java.lang.String)
如果你是要寫在 JSP 時,application.getRealPath(java.lang.String)

另外如果你的 test2.jsp 是放在 {webapp}\ROOT\project\News\test2.jsp
的確只能找到 {webapp}\ROOT 的路徑
所以還要搭配
1 request.getRequestURI()
2 request.getRequestURL()
3 request.getServletPath()

才能完整做出你的需求

PS. 反正都能解決 .. 所以不需求再做一個 method 來直接取得 所在local端的絕對位置
分享到:
评论

相关推荐

    GetRealPath.java

    用于添加其他应用列表打开文件获取微信QQ 分享过来的文件真实路径,并替换路径中存在的编码格式问题,解决文件上传媒体库找不到传输的文件,可以在微信,QQ中直接选择自己的应用打开,并获取到文件的路径!

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

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

    Struts Updownload 源码

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

    struts2+spring2+ibates

    2、在sping配置中注意单元测试里,xml文件的路径问题,要用绝对路径。 3、struts.xml中命名空间和拦截器的使用。 4、sqlmapconfig.xml中传入参数和result的设置,只需要将得到的值result映射到有此属性的类对象. 5、...

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

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

    getServletContext()空指针异常的原因

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

    iReport4.5打印实例

    .getRealPath("/"+jrprint)); JasperPrint jasperPrint = JasperFillManager.fillReport(reportFile.getPath(),null,dataSource);//执行报表程序 程序中都很明了 大家肯定会问print.jsp怎么会调用到AppletServlet....

    在JSP中处理虚拟路径

    getRealPath()方法JSP servlet API提供了getRealPath(path)方法,返回给定虚拟路径的真实路径,如果转换错误,则返回null。getRealPath语法定义:public java.lang.String getRealPath(java.lang.Stri

    Java获取*路径实现探讨

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

    jsp 对文件的操作

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

    fileutil工具类 处理文件流工具

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

    大漠插件7.1901

    3. 解决上个版本有几率造成程序假死的问题,以及CPU有可能暴涨的问题 4. 解决EnumWindow在枚举的窗口非常多时(超过大概500个),返回结果会不全的BUG 5. 恢复对32位系统的SetSimMode 模式1和2,以及32位系统的memory ...

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

    // 设置字符编码为UTF-8, 统一编码,处理出现乱码问题 response.setCharacterEncoding("UTF-8"); // 实例化一个硬盘文件工厂,用来配置上传组件ServletFileUpload DiskFileItemFactory dfif = new ...

    Servlet实现文件下载

    Servlet实现文件下载public void doGet(HttpServletRequest request, HttpServletResponse response) ... String str = this.getServletContext().getRealPath("/download/隐形的翅膀 - 张韶涵正版.mp3");

    struts1.2 上传和下载

    struts1.2 的上传和下载, 如果需要得到相对路径, 加一个 String path=request.getSession().getServletContext().getRealPath(); 就行了 ,这个就是comcat下的项目路径。

    图片上传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 = ...

    JSF文件下载实现

    String realName = servletContext.getRealPath(path) + "/" + fileName; HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext .getCurrentInstance().getExternalContext()....

    java的运用个人经典相册

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

    新浪在线编辑器 jsp版 可上传

    由asp版本修改。补充:内容的存取,特殊字符(如引号)最好replace转义处理。上传bean是src\com\UploadBean.java 上传处理在\Edit\editor\upload.jsp 部分浏览器预览本地图片小红叉可改路径...如request.getRealPath("/")

Global site tag (gtag.js) - Google Analytics