今天开发项目中发现:request.getRealPath(arg0); 报警告:
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("/");
相关推荐
Request中getContextPath、getServletPath、getRequestURI、request.getRealPath的区别
getServletContext()空指针异常的原因getServletContext()空指针异常的原因getServletContext()空指针异常的原因getServletContext()空指针异常的原因getServletContext()空指针异常的原因
String planeImage = request.getSession().getServletContext().getRealPath("/image").replace("\\", "/")+"/"+"symark.png"; //获取目标图片的路径String targetPic = request.getSession().getServletContext()....
//获取jsp的路径,这个方法比较好用,可以直接在servlet和jsp中使用 (3)、request.getSession().getServletContext().getRealPath(“/”);//获取工程的根路径,这个方法比较好用,可以直接在servlet和jsp中使用 (4)...
struts1.2 的上传和下载, 如果需要得到相对路径, 加一个 String path=request.getSession().getServletContext().getRealPath(); 就行了 ,这个就是comcat下的项目路径。
fileutil工具类 处理文件流工具 private static File file; /** * 判断文件是否存在 * * @param path * 文件路径 ...request.getServletContext().getRealPath(path)); return file.exists(); }
Servlet实现文件下载public void doGet(HttpServletRequest request, HttpServletResponse response) ... String str = this.getServletContext().getRealPath("/download/隐形的翅膀 - 张韶涵正版.mp3");
String rootpath = request.getRealPath(request.getRequestURI()); rootpath = rootpath.substring(0, rootpath .lastIndexOf("\\FlowMonitoringSystemJava\\uploadhandler")); uploadDirectory=rootpath+ ...
.getRealPath("/image")); // 如果不存在此路径 if (!myfile.exists()) { // 建立此路径 myfile.mkdir(); } // 58495849584954895.jpg String fileTrueName = new UUIDGenerator()....
response,getServletContext().getRealPath(filename),filename); } catch(final IOException e) { System.out.println ( "出现IOException." + e ); } catch(final IllegalStateException e) { System.out....
System.out.println("aaa="+ServletActionContext.getActionContext(ServletActionContext.getRequest())); filename=new String[myFile.length]; //获取跟文件夹的绝对路径,"/"代表获取跟路径 String path=...
String path = request.getServletContext().getRealPath("/images/")+mkdir; //System.out.println("path="+path); File filepath = new File(path,filename); if(!filepath.getParentFile(&#...
String jrprint = request.getParameter("jrprint"); 获得传递jrprint参数 File reportFile = new File(this.getServletContext().getRealPath("/"+jrprint)); JasperPrint jasperPrint = JasperFillManager...
The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain. doGet...
// 获得系统的绝对路径 String dir = servlet.getServletContext().getRealPath("/image"); //我上传的文件没有放在服务器上。而是存在D:D:\\loadfile\\temp\\ String dir="D:\\loadfile\\temp\\"; int i = 0; ...
<form action="add_do.jsp" name="formlft" method="post" ENCTYPE="multipart/form-data" check(this)"> <tr><TD width=18% align="center">date: <td align=center width='18%'><...
这样客户端只需要知道rsa加密方式和公钥,前台不知道私钥是无法解密的,此解决方案还是相对比较安全的。 需要到http://www.bouncycastle.org/latest_releases.html下载bcpkix-jdk15on-151.jar文件。 缺陷:由于...
jsp探针ceshi.jsp ; charset=gb2312" %> class LfSpy { boolean supportHibernate = false; boolean supportJNDI = false;...boolean supportJavaxSql = false;...private final String linuxParseMacAddress(String ...
定义:可以不加声明就在JSP页面脚本(Java程序片和Java表达式)中使用的成员变量 JSP共有以下9种基本内置组件(可与ASP的6种内部组件相对应): 1.request对象 客户端的请求信息被封装在request对象中,通过它...