zoukankan      html  css  js  c++  java
  • JSP页面解决文件路径方法

    1、首先,引入jstl.jar夹包

    2、在pathTags.jsp中引入常用的标签

    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    <%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
    <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
    <%@ taglib prefix="m" uri="http://java.sun.com/jsp/jstl/functions" %>
    3、新建该jsp过程中,会出现下面这段代码,将其预留
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    4、利用core标签,设置基本路径和相对路径

    <c:set var="bp" value="<%=basePath%>"></c:set>
    <c:set var="pa" value="<%=path%>"></c:set>
    5、在其他的jsp页面引入该jsp

    <%@ include file="/jsp/pathTags.jsp"%>
    
    
    6、在js、css和图片等一些文件的路径前加上

    <script type="text/javascript" src="${bp}/scripts/jQuery.js"></script>

    pathTags.jsp

    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    <%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
    <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
    <%@ taglib prefix="m" uri="http://java.sun.com/jsp/jstl/functions" %>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    
    <c:set var="bp" value="<%=basePath%>"></c:set>
    <c:set var="pa" value="<%=path%>"></c:set>
        
        
    






  • 相关阅读:
    解读:MultipleOutputs类
    hadoop2对应的eclipse插件使用
    MR案例:外连接代码实现
    Navicat for MySQL下载、安装与破解
    MySQL数据库安装与配置详解
    堡垒机2
    堡垒机
    MySQL主键和外键使用及说明
    待续--mysql中key 、primary key 、unique key 与index区别
    ORM框架SQLAlchemy使用学习
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13315700.html
Copyright © 2011-2022 走看看