🅰️ 定义通用变量
在Jsp中,有两种方式定义变量
- 使用
<%%>语法
配合req.setAttribute()
- 使用
<%!%>声明变量
,相当于给jsp定义field
对于第二种方式
**,定义的变量不能在el表达式中使用(el对象获取不到)
。所以采用第一种方式。
<!--
这里单独定义了一个文件,专门存放通用变量,叫var.jsp
-->
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
String basePath = String.format("%s://%s:%s%s", request.getScheme(),
request.getServerName(),
request.getServerPort(),
request.getContextPath());
request.setAttribute("basPath",basePath);
%>
🅱️ 所有页面引入 - 通用变量
引入方式有两种
<%@ include file='' %>
- include指令<%c:import url='xxx'%>
配合<