zoukankan      html  css  js  c++  java
  • jsp常见获取地址函数之间的不同

    对jsp中常用地址获取函数进行区分测试函数:

    test1.jsp=======================
    
    <a href ="test.jsp?p=fuck">跳转到test2</a>
    
    test2.jsp=======================
    
    <%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    
    out.println("basePath:"+basePath);
    out.println("<br/>");
    out.println("getContextPath:"+request.getContextPath());
    out.println("<br/>");
    out.println("getServletPath:"+request.getServletPath());
    out.println("<br/>");
    out.println("getRequestURI:"+request.getRequestURI());
    out.println("<br/>");
    out.println("getRequestURL:"+request.getRequestURL());
    out.println("<br/>");
    out.println("getRealPath:"+request.getRealPath("/"));
    out.println("<br/>");
    out.println("getServletContext().getRealPath:"+getServletContext().getRealPath("/"));
    out.println("<br/>");
    out.println("getQueryString:"+request.getQueryString());
    
    %>

    显示结果:

    basePath:http://localhost:8080/test/
    
    getContextPath:/test 
    getServletPath:/test.jsp 
    getRequestURI:/test/test.jsp 
    getRequestURL:http://localhost:8080/test/test.jsp 
    getRealPath:D:\Tomcat 6.0\webapps\test\ 
    getServletContext().getRealPath:D:\Tomcat 6.0\webapps\test\ 
    getQueryString:p=fuck
  • 相关阅读:
    [GO]使用map生成 json
    [GO]通过结构体生成json
    [GO]正则表达式
    [GO]字符串的使用
    [GO]revoer的应用
    [GO]panic的应用
    微信公众平台自定义菜单及高级接口PHP SDK
    论MySQL何时使用索引,何时不使用索引
    MYSQL explain详解
    Mysql两种存储引擎的优缺点
  • 原文地址:https://www.cnblogs.com/2017Crown/p/7137278.html
Copyright © 2011-2022 走看看