jsp页面设置绝对路径

例子: 设置完之后就随便jsp页面放在哪个文件夹都可以加载到资源了

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%
    String path=request.getContextPath();
    String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
    <meta charset="utf-8">
    <meta name="viewport" content="user-scalable=no,width=device-width,initial-scale=1,maximum-scale=1">
    <title>yun70商户注册</title>
    <link rel="stylesheet" type="text/css" href="<%=path%>/css/common.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/css/login.css">
    <script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script>
</head>

   

原文地址:https://www.cnblogs.com/suiyisuixing/p/7645977.html