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

两种方式

 

<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>

你可能感兴趣的:(java,c,jsp,String)