[转]JSTL 与 JSP 或者 Java 相互传递变量的代码

原文地址:http://blog.csdn.net/joyous/article/details/6689861

两种方式

 

<c:set var="s1" value="This is One" scope="request" />

out.print(request.getAttribute("s1") ;


<c:set var="s2" value="This is Two"/>

out.print(pageContext.getAttribute("s2"));

 

----------------------------------------------------

JSTL 变量由 JSP 读取

 

<c:set var="JspValue1" value="Java Language One" scope="request" /> 
<c:set var="JspValue2" value="Java Language Two"/>

<%
String JspValue3 = request.getAttribute("JspValue1").toString();
String JspValue4 = pageContext.getAttribute("JspValue2").toString();
          
out.print(JspValue3);
out.print(JspValue4);
%>

 

----------------------------------------------------

 

JSP 变量由 JSTL 读取

String strContextPath = request.getContextPath();
 pageContext.setAttribute("ContextPath", strContextPath);

..

<c:out value="${ContextPath}"></out>

posted @ 2017-09-13 10:56  dirgo  阅读(551)  评论(0编辑  收藏  举报