Test the JSTL expression

Source: Internet
Author: User
Tags tld

JSTL is generally used together with EL expressions. By providing standard implementations for common functions of most Web applications, JSTL helps accelerate the development cycle. I. Relationship between JSTL and El expressions EL and operations provided by the four JSTL custom tag libraries allow page authors to implement presentation layer logic without using script elements (no need to write java code for presentation layer programs ), this greatly simplifies the maintenance of JSP applications. Ii. Usage: 1. If you only use the EL expression, you do not need to introduce any jar packages, as long as the jsp/servlet container implements J2EE1.4/Servlet2.4 and JSP2.0 specifications, you can configure and use JSTL labels: (1) Change jstl. jar and standard. jar copy to WEB-INF/lib (2) in jsp page use: Using taglib command to introduce the label Library (which can be used to introduce which) <% @ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix =" c "%> <% @ taglib uri =" http://java.sun.com/jsp/jstl/functions "prefix =" fn "%> <% @ taglib uri =" http://java.sun.com/jsp/jstl/fmt" prefix = "fmt" %> (3) use a custom function: * define the class MyFu. Nctions, the method must provide a tld description file for static global * (just write it like other standard tld files ), put tld in any directory under the WEB-INF or WEB-INF * in jsp using taglib introduced * in EL expression using prefix + colon + function name call 3, test example: project Overview 1. EL expression Servlet [java] package com. jialin. jstl; import java. io. IOException; import java. util. arrayList; import java. util. hashMap; import java. util. list; import java. util. map; import javax. servlet. servletException; import javax. servlet. http. httpServlet; import jav Ax. servlet. http. httpServletRequest; import javax. servlet. http. httpServletResponse;/*** test El expression Servlet * @ author jialin **/public class ElServlet extends HttpServlet {protected void doGet (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {// TODO Auto-generated method stub doPost (req, resp);} protected void doPost (HttpServletRequest request, HttpServletRe Response se response) throws ServletException, IOException {Group group Group = new group (); Group. setGroupName ("group 1"); // Common Object User user = new User (); user. setGroup (group); user. setName ("Zhang San"); user. setAge (17); // map Map map = new HashMap (); map. put ("k1", "k1value"); map. put ("k2", "k2value"); // String Array String [] strArr = new String [] {"a", "B", "c ", "d"}; // object array \ User [] arrUser = new User [10]; for (int I = 0; I <arrUser. length; I ++) {arrUser [I] = new User (); arrUser [I]. setName ("Zhang San" + I);} // List listUser = new ArrayList (); for (int I = 0; I <= 10; I ++) {User usr = new User (); usr. setName ("War 3" + I); listUser. add (usr);} // put the request. setAttribute ("arrUser", arrUser); request. setAttribute ("listUser", listUser); request. setAttribute ("arr", strArr); request. setAttribute ("map", map); reque St. setAttribute ("user", user); request. setAttribute ("v1", ""); request. setAttribute ("v2", new ArrayList (); request. setAttribute ("v3", null); request. setAttribute ("v4", "434"); request. setAttribute ("hello", "Hello World"); // forward the request. getRequestDispatcher ("/ElTest. jsp "). forward (request, response) ;}} package com. jialin. jstl; import java. io. IOException; import java. util. arrayList; import java. util. HashMap; import java. util. list; import java. util. map; import javax. servlet. servletException; import javax. servlet. http. httpServlet; import javax. servlet. http. httpServletRequest; import javax. servlet. http. httpServletResponse;/*** test El expression Servlet * @ author jialin **/public class ElServlet extends HttpServlet {protected void doGet (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {// TODO Auto-generated method stubdoPost (req, resp);} protected void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {Group group = new Group (); group. setGroupName ("group 1"); // Common Object User user = new User (); user. setGroup (group); user. setName ("Zhang San"); user. setAge (17); // mapMap map = new HashMap (); map. put ("k1", "k1value"); map. put ("k2", "k2val Ue "); // String Array String [] strArr = new String [] {" a "," B "," c "," d "}; // object array \ User [] arrUser = new User [10]; for (int I = 0; I <arrUser. length; I ++) {arrUser [I] = new User (); arrUser [I]. setName ("Zhang San" + I);} // ListList listUser = new ArrayList (); for (int I = 0; I <= 10; I ++) {User usr = new User (); usr. setName ("War 3" + I); listUser. add (usr);} // put requestrequest. setAttribute ("arrUser", arrUser); request. SetAttribute ("listUser", listUser); request. setAttribute ("arr", strArr); request. setAttribute ("map", map); request. setAttribute ("user", user); request. setAttribute ("v1", ""); request. setAttribute ("v2", new ArrayList (); request. setAttribute ("v3", null); request. setAttribute ("v4", "434"); request. setAttribute ("hello", "Hello World"); // forward the request. getRequestDispatcher ("/ElTest. jsp "). forward (request, response) ;}} Jsp [html] <% @ page language = "java" contentType = "text/html; charset = GB18030" pageEncoding = "GB18030" %> <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.