通过el表达式配置使jsp直接调用java静态方法

1.创建java静态方法

package demo;

import java.util.Map;

/**
 * Created by Administrator on 2016/3/6.
 */
public class Demo {

    public static String demo(){
        String str = "11111111111";
        return str;
    }

}

2.在WEB-INF目录下创建.tld文件,我这里是sdk.tld



    1.2
    sdk

    
        demo
        demo.Demo
        java.lang.String demo()
    

3.在web.xml中配置sdk.tld




    
        
            Demo
            /WEB-INF/sdk.tld
        
    



4.编写jsp文件,并且引入sdk.tld

<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/3/6
  Time: 21:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="sdk" uri="/WEB-INF/sdk.tld"%>

  
    
  
  
    trewtrewtwert${sdk:demo()}
  

你可能感兴趣的:(java学习)