EL運算式能調用的函數

來源:互聯網
上載者:User

先定義需要用el調用函數所在的類:

注意el所調用的方法必須是static的!

Java代碼
  1. package com.qingsoft.el.function;   
  2.   
  3. public class CheckUsername {   
  4.   
  5.     public static boolean check(Userinfo userinfo)   
  6.     {   
  7.         if(userinfo.getUsername().equals("admin"))   
  8.         {   
  9.             return true;   
  10.         }   
  11.         return false;   
  12.     }   
  13. }   

 

接下來定義tld檔案如下:

 

XML/HTML代碼
  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2.   
  3. <taglib xmlns="http://java.sun.com/xml/ns/javaee"  
  4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  5.     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"  
  6.     version="2.1">  
  7.        
  8.   <description>JSTL 1.1 core library</description>  
  9.   <display-name>JSTL core</display-name>  
  10.   <tlib-version>1.1</tlib-version>  
  11.   <short-name>qsfun</short-name>  
  12.   <uri>http://www.qingsoft.net/el/function</uri>  
  13.   
  14.      <function>  
  15.             <description>check username</description>  
  16.             <name>check</name>  
  17.             <function-class>com.qingsoft.el.function.CheckUserName</function-class>  
  18.             <function-signature>boolean   check(com.qingsoft.vo.Userinfo)</function-signature>  
  19.     </function>  
  20.        
  21. </taglib>  

 

下面就可以在jsp檔案中使用了:

首先匯入標籤庫:

 

Java代碼
  1. <%@taglib prefix="qs" uri="http://www.qingsoft.net/el/function" %>  

 

下面看如何使用: 

Java代碼
  1. <%   
  2.     Userinfo userinfo = new Userinfo();   
  3.     userinfo.setUsername("admin");   
  4.     request.setAttribute("userinfo",userinfo);   
  5.     %>   
  6.        
  7.     ${qs:check(userinfo)} 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.