${ma.category}類似下面個功能
String category = request.getParameter("ma.category");
category = category.replaceAll("1","辦公設備");
out.print(category);
大家發表點看法
String category = request.getParameter("ma.category");
category = category.replaceAll("1","辦公設備");
out.print(category);
大家發表點看法
第一你可以自定义el函数1.写一个Java类的静态方法
2.写标签库描述符(tld)文件,在tld文件中描述自定义函数。
TLD文件中的<uri> 元素用指定该TLD文件的URI,在JSP文件中需要通过这个URI来引入该标签库描述文件。
<function>元素用于描述一个EL自定义函数,其中:
<name>子元素用于指定EL自定义函数的名称。
<function-class>子元素用于指定完整的Java类名
3.在JSP页面中导入和使用自定义函数第二使用JSTL在页面中使用JSTL定义的EL函数:
导入..
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>fn:replace方法可以进行替换fn:replace("abc", "b", "a")的返回值为字符串“aac”
办公设备
</c:if><c:if test="${ma.category==2}">
家居设备
</c:if>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>${fn:replace(ma.category,"1","辦公設備")}
pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<html>
<body>
<%
//模拟加数据
request.setAttribute("ma.category", "1 2 1");
%>
<input type="text" id="a" name="a" value='${fn:replace(requestScope["ma.category"], "1", "辦公設備")}'>
</body>
</html>
<function>
<description>
Returns a string resulting from replacing in an input string all occurrences
of a "before" string into an "after" substring.
</description>
<name>replace</name>
<function-class>org.apache.taglibs.standard.functions.Functions</function-class>
<function-signature>java.lang.String replace(java.lang.String, java.lang.String, java.lang.String)</function-signature>
<example>
${fn:replace(text, "-", "•")}
</example>
</function>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
加上下面这句
${fn:replace(ma.category,"1","辦公設備")}
说找不到标签
The class org.apache.taglibs.standard.functions.Functions specified in TLD for the function fn:replace cannot be found: org.apache.taglibs.standard.functions.Functions
导入JSTL后不用配置tld文件...直接用就好了 他给你配置好了
确保下载了最新的jstl包并放到了lib目录中,然后页面中直接引taglib并写EL好了