request.getContextPath()等的常用
2016-09-19 16:26
405 查看
1、request.getScheme() 返回当前链接使用的协议;比如,一般应用返回http;SSL返回https;
2、在程序中的应用如下:
Java代码
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
<base href="<%=basePath%>">
3、request 的常用方法:
request.getSchema()可以返回当前页面使用的协议,http 或是 https;
request.getServerName()可以返回当前页面所在的服务器的名字;
request.getServerPort()可以返回当前页面所在的服务器使用的端口,就是80;
request.getContextPath()可以返回当前页面所在的应用的名字;
假定你的web application 名称为news,你在浏览器中输入请求路径:
http://localhost:8080/news/main/list.jsp
1.1 System.out.println(request.getContextPath());
打印结果:/news
1.2 System.out.println(request.getServletPath());
打印结果:/main/list.jsp
1.3 System.out.println(request.getRequestURI());
打印结果:/news/main/list.jsp
1.4 System.out.println(request.getRealPath("/"));
打印结果:F:\Tomcat 6.0\webapps\news\test
2、在程序中的应用如下:
Java代码
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
<base href="<%=basePath%>">
3、request 的常用方法:
request.getSchema()可以返回当前页面使用的协议,http 或是 https;
request.getServerName()可以返回当前页面所在的服务器的名字;
request.getServerPort()可以返回当前页面所在的服务器使用的端口,就是80;
request.getContextPath()可以返回当前页面所在的应用的名字;
假定你的web application 名称为news,你在浏览器中输入请求路径:
http://localhost:8080/news/main/list.jsp
1.1 System.out.println(request.getContextPath());
打印结果:/news
1.2 System.out.println(request.getServletPath());
打印结果:/main/list.jsp
1.3 System.out.println(request.getRequestURI());
打印结果:/news/main/list.jsp
1.4 System.out.println(request.getRealPath("/"));
打印结果:F:\Tomcat 6.0\webapps\news\test
相关文章推荐
- 【转】request.getcontextPath() 详解
- request.getContextPath详解
- String path = request.getContextPath(....拼装当前网页的相对路径
- request.getcontextPath()详解
- getContextPath、getServletPath、getRequestURI的区别
- Request中getContextPath、getServletPath、getRequestURI、getRealPath
- request.getContextPath();
- request.getcontextPath()_详解
- request中的getContextPath()和getServletPath()和getRequestURI()和getRealPath()的区别~~
- Request中getContextPath、getServletPath、getRequestURI、request.getRealPath的区别
- Request中getContextPath、getServletPath、getRequestURI、request.getRealPath的区别
- ServletActionContext.getRequest().getServletPath()错误的解决方法
- request.getcontextPath() 详解
- request.getContextPath()用el表达式怎么写,绝对路径:request.getRealPath
- request.getContextPath()的用法
- Request中getContextPath、getServletPath、getRequestURI、request.getRealPath的区别
- Request中getContextPath、getServletPath、getRequestURI、getRequestURL、getRealPath的区别
- Request中getContextPath、getServletPath、getRequestURI、request.getRealPath的区别
- request.getRequestURI() 、request.getRequestURL() 、request.getContextPath()、request.getServletPath()区别
- Request中getContextPath、getServletPath、getRequestURI、request.getRealPath的区别