smbms项目,jsp文件加载不到css样式文件

smbms项目,jsp文件加载不到css样式文件

尝试过更换很多种路径,最后找到解决方法

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" %>



    <%--
    把项目中的${pageContext.request.contextPath}都替换成了<%=basePath%>
    --%>

    <%
        String path = request.getContextPath();
        String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
        System.out.println(path);
        System.out.println(basePath);
    %>

    
    系统登录 - 超市订单管理系统
    
    


    

超市订单管理系统

${error}

smbms项目,jsp文件加载不到css样式文件_第1张图片

把项目中的${pageContext.request.contextPath}都替换成了<%=basePath%>

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

原因:

  • ${pageContext.request.contextPath}只能拿到项目名称 不是我们想要的地址
  • ${pageContext.request.contextPath} = /(项目名称)
  • basePath = http://localhost:8080/(项目名称)

ps:

测试了一下,好像只适用于加载css样式文件,js好像不行。。

js还是用${pageContext.request.contextPath}引入

你可能感兴趣的:(JavaWeb)