js中使用el表达式:
var contextPath = "${contextPath}";
js中使用jsp定义的变量:
<%
String firstname = "wang";
%>
<script type="text/javascript">
function out()
{
var name = '<%=firstname%>';
alert('MyFirstName: ' + name);
}
</script>
jstl中使用el表达式:
<c:set var="contextPath" value="${pageContext.request.contextPath}" scope="application"/>
jstl中获取session:
session.setAttribute("age","123");
${sessionScope.age} 在页面上显示的就是123了
sessionScope指的是session的范围,类似还有requestScope,pageScope,contextScope
然后后面的age表示的是set属性时的key值
jsp中获取session:
session是jsp的内置对象,所以你可以直接写在jsp的
<%
session.setAttribute("a", b); //把b放到session里,命名为a,
String M = session.getAttribute(“a”).toString(); //从session里把a拿出来,并赋值给M
%>