zoukankan      html  css  js  c++  java
  • jsp 中的路径

    一些小盆友总是询 jsp 的一些路径到底指的是啥 今天就来扒拉一下 

    比如我在jsp中写了一段Java代码 :

    一:获取路径:访问路径

    jsp中访问后台需要url,一般不会把url写死,会使用代码来获取基本路径,以便以后的修改。

    1.path = request.getContextPath(); :-------/webName 项目名称 
    2.request.getScheme() :协议名字 ----------------http
    3.request.getServerName():服务器名字 -------localhost
    4.request.getServerPort():端口号------8080

    5.request.getServletPath(),返回当前页面所在目录下全名称:/course/index.jsp;

    6.request.getRequestURL(),返回IE地址栏地址:http://localhost:8080/WebName/course/index.jsp;

    7.request.getRequestURI() ,返回包含工程名的当前页面全路径:/webName/course/index.jsp


    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

    http://localhost:8080/WebName/

    举例

    String path = request.getContextPath(); ------------ /course

    request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/" ----http://localhost:8080/course/

  • 相关阅读:
    Js~数组的操作push,pop,shift,unshift
    SqlServer 字段类型详解
    数据库设计三大范式
    HTML 解析类库HtmlAgilityPack
    设计模式六大原则
    表达式目录树
    在Web.config或App.config中的添加自定义配置
    史上最全 ——LINQ to SQL语句
    C# 加密解密类
    WebService登陆验证四种方式
  • 原文地址:https://www.cnblogs.com/JonaLin/p/14041403.html
Copyright © 2011-2022 走看看