Java/JSTL/HTML Output

Материал из Java эксперт
Перейти к: навигация, поиск

Out Default Examples

   <source lang="java">

<%@ taglib uri="http://java.sun.ru/jstl/core" prefix="c" %> <html>

 <head>
   <title>Out Default Examples</title>
 </head>
 <body>testit = 
 <c:out value="${testit}" default="Default Value" />
 </body>

</html>


      </source>
   
  
 
  



Output a table

   <source lang="java">

<%@ taglib uri="http://java.sun.ru/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.ru/jstl/core-rt" prefix="c-rt" %> <html>

 <head>
   <title>Count to 10 Example(tracking even and odd)</title>
 </head>
 <body>
<c:forEach var="i" begin="1" end="10" varStatus="status"> <jsp:useBean id="status" type="javax.servlet.jsp.jstl.core.LoopTagStatus" /> <c-rt:choose> <c-rt:when test="<%=status.getCount()%2==0%>"> <c:set var="color" value="#eeeeee" /> </c-rt:when> <c-rt:otherwise> <c:set var="color" value="#dddddd" /> </c-rt:otherwise> </c-rt:choose> <td width="200" bgcolor="<c:out value="${color}"/>"> <c:out value="${i}" /> </td> </c:forEach> </table> </body> </html> </source>

Out with Tag Escaping Examples

   <source lang="java">

<%@ taglib uri="http://java.sun.ru/jstl/core" prefix="c" %> <html>

 <head>
   <title>Out with Tag Escaping Examples</title>
 </head>
 <body>
   <c:set var="test" scope="page">
   
   
   </c:set>

Out With Encode=true

   <c:out value="${test}" escapeXml="true" />
   

Out With Encode=false

   <c:out value="${test}" escapeXml="false" />
   
</body>

</html>


      </source>
   
  
 
  



Simple calculation and output

   <source lang="java">

<%@ taglib uri="http://java.sun.ru/jstl/core" prefix="c" %> <html>

 <head>
   <title>Out Examples</title>
 </head>
 <body>

Out Example

 10 * 3 = 
 <c:out value="${10*3}" />
 
</body>

</html>


      </source>