jstl最常用的标签之<c:out>

一 定义
<c:out>用于把计算的结果输出到JspWrite对象。
 
二 代码
<%@ page language = "java" import = "java.util.*,com.cakin.domain.*" pageEncoding = "utf-8" %>
<!--  引入 jstl 标签库-->
<%@ taglib prefix = "c"   uri = " http://java.sun.com/jsp/jstl/core" ; %>
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" ; >
< html >
  < head >    
    < title > My JSP 'c_out.jsp' starting page </ title >
  </ head >
  < body >
  <%
         //这句话本身应该放在控制器中,这里只是为了测试
         //如果我们的域对象中有相同的属性名,c:out的优先级是:pageContext>request>session>application
        request.setAttribute( "abc" , "您好" );
        session.setAttribute( "abcd" , "您好<a href=' http://www.baidu.com'>百度</a>" ; );
        application.setAttribute( "abc" , "您好2" );
        pageContext.setAttribute( "abc" , "您好3" );
        User user= new User();
        user.setName( "小明" );
        user.setAge(30);
        request.setAttribute( "user1" ,user);
        
         //out.println("hello,wolrd");
   %>
   < h3 > 基本输出 </ h3 >
   < c:out value = "Hello,world" ></ c:out >
   < h3 > 如何输出request/session/application/pageContext域对象的数据 </ h3 >
   < c:out value = " ${abc} " ></ c:out >
   < h3 > 输出默认值 </ h3 >
   < c:out value = " ${abcc} " default = "没有值" ></ c:out >
   < h3 > html 样式输出,默认true表示文本 false以 html 形式 </ h3 >
   < c:out value = " ${abcd} " default = "没有值" escapeXml = "false" ></ c:out >
   < h3 > 如何输出对象 </ h3 >
   < c:out value = " ${user1.name} " ></ c:out > || < c:out value = " ${user1.age} " ></ c:out ></ br >
   ${user1.name}@@${user1.age*20}
  </ body >
</ html >
 
三 测试结果


 

猜你喜欢

转载自cakin24.iteye.com/blog/2397946