获得绝对路径
···
File file= new File(path);
System.out.println(file.getAbsolutePath());
···
获得Tomcat路径
这是一段加载在jsp中的java代码
<%
//______________________write json here______________________/
//设置响应内容类型
response.setContentType("text/html;charset=UTF-8");
// 处理中文
String Mid =new String(request.getParameter("Mid").getBytes("ISO8859-1"),"UTF-8");
System.out.println(Mid);
int mid=Integer.parseInt(request.getParameter("Mid"));
WriteHomepageJson.movieDetail(mid);
WriteHomepageJson.similarMovie(mid);
WriteHomepageJson.movieComment(mid);
System.out.println("tomcat绝对路径:"+request.getServletContext().getRealPath("/"));
System.out.println("init jsp!");
System.out.println(mid);
%>