从tld调用Java类的静态方法时,我遇到一些问题,例如在运行jsp文件时,它始终显示此${test:concat("java")}
作为输出,它甚至不调用java类。
index.jsp文件
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="test" uri="/WEB-INF/SubstrDescriptor.tld"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>JSP Custom Taglib example: Substr function</title>
</head>
${test:concat("java")}
</html>
SubstrDescription.tld
<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0">
<tlib-version>2.0</tlib-version>
<function>
<name>concat</name>
<function-class>java4s.Demo</function-class>
<function-signature>java.lang.String doMyStuff( java.lang.String )
</function-signature>
</function>
</taglib>
Demo.java
package java4s;
public class Demo {
public static String doMyStuff( String myparam )
{
System.out.println(myparam);
return myparam;
}
}
答案 0 :(得分:0)
你应该尝试总是给它起相同的名字。你写了
<function-signature>java.lang.String doMyStuff( java.lang.String )
</function-signature>
什么时候应该
<function-signature>java.lang.String concat( java.lang.String )
</function-signature>
答案 1 :(得分:0)
如下所述进行少量更改并再次检查。
<uri>SubstrDescriptor</uri>
<%@ taglib prefix="test" uri="SubstrDescriptor"%>
。请查看可能有助于您更好理解的类似帖子How to call a static method in JSP/EL?。
JSP:
<%@ taglib prefix="test" uri="SubstrDescriptor"%>
<body>
${test:concat("java")}
</body>
SubstrDescription.tld:
<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0">
<tlib-version>2.0</tlib-version>
<uri>SubstrDescriptor</uri>
<function>
<name>concat</name>
<function-class>java4s.Demo</function-class>
<function-signature>java.lang.String doMyStuff( java.lang.String )
</function-signature>
</function>
</taglib>
项目结构:
WebContent
|
|__WEB-INF
| |
| |__SubstrDescription.tld
| |__web.xml
|
|__index.jsp