JSTL核心库常用标签举例

JSTL核心库常用标签举例(详解)


struts-config.xml:


          "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
          "http://struts.apache.org/dtds/struts-config_1_3.dtd">


 
        type="com.yulin.struts.JSTLCoreAction"
     >
    
  

   


演示的JSP页面(jstlcore.jsp):

<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>




Test JSTL


Test JSTL




  • TEST c:out


  • core(el): ${core }

    core(el.empty): ${empty core }

    core(default):

    core(default):

    core(default="123456"):



    html(el): ${core2 }

    html(el.requestScope): ${requestScope.core2 }

    html(default):

    html(escapeXml="true"):

    html(escapeXml="false"):

    html(default="输出html文件"):

    html(default="输出html文件"escapeXml="false"):



  • TEST c:set c:remove



  • temp(c:set): ${temp }


    temp(c:remove): ${temp }



  • TEST c:if



  • v1小于v2,${r }



    v2da于v1,${r }




  • TEST c:choose,c:when,c:otherwise




  •    v1小于v2





       v1da于v2



       v1xiaoyuv2





  • TEST c:forEach varStatus="vs" begin="4" end="40" step="5"




  •   
      
      


      
      

       
      
      
      
       
        
         
          
         

         
          
         

        

        

         
         
         
        
      
      

    UsernameAgeGroup
    there is no info!
    ${user.username }${user.age }${user.group.name }



  • TEST c:fortokens delims="," var="f"



  • ${f }




  • TEST c:catch



  • <%
    Integer.parseInt("sss");
    %>

    ${e }



  • TEST c:import





  • TEST c:url c:param






  • ${turl }



  • TEST c:redirect [context]url


  • 所需的JSTLCoreAction页面(JSTLCoreAction.java):

    package com.yulin.struts;

    import java.util.ArrayList;
    import java.util.List;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;

    public class JSTLCoreAction extends Action {

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
       request.setAttribute("core", "core");
       request.setAttribute("core1", "");
       //输出html文件
       request.setAttribute("core2", "输出html文件");
       request.setAttribute("core3", "");
       request.setAttribute("v1", 1);
       request.setAttribute("v2", 2);
       request.setAttribute("v3", "");
     
       List userList = new ArrayList();
       for(int i=0;i<50;i++){
        Group g = new Group();
        g.setName("China");
        User u = new User();
        u.setUsername("LinZhang" + i);
        u.setAge(23);
        u.setGroup(g);
        userList.add(u);
       }
       request.setAttribute("userList", userList);
     
       request.setAttribute("fortokens", "a,b,c,d,e,f,g");
       return mapping.findForward("success");
    }

    }

    涉及到的User(User.java)和Group(Group.java)页面:

    User.java:

    package com.yulin.struts;

    public class User {
    private String username;
    private int age;
    private Group group;
    public String getUsername() {
       return username;
    }
    public void setUsername(String username) {
       this.username = username;
    }
    public int getAge() {
       return age;
    }
    public void setAge(int age) {
       this.age = age;
    }
    public Group getGroup() {
       return group;
    }
    public void setGroup(Group group) {
       this.group = group;
    }
    }

    Group.java:

    package com.yulin.struts;

    public class Group {
    private String name;

    public String getName() {
       return name;
    }

    public void setName(String name) {
       this.name = name;
    }
    }
     

    你可能感兴趣的:(JS)