我无法调用我在 JSP 中创建的自定义标记。
标签描述符库的相关部分:
<!-- username tag -->
<tag>
<name>username</name>
<tag-class>abc.xyz.UserNameTagHandler</tag-class>
<body-content>empty</body-content>
</tag>
Java类是:
public class UserNameTagHandler extends TagSupport {
public int doTag() throws JspException {
HttpServletRequest httpServletRequest = (HttpServletRequest)pageContext.getRequest();
String username = httpServletRequest.getRemoteUser();
if (username==null) {
username = "Guest";
} else {
username = username.replaceFirst("@.*$", "");
}
JspWriter jspWriter = pageContext.getOut();
try {
jspWriter.print(username);
} catch (IOException e) {
e.printStackTrace();
}
return SKIP_BODY;
}
}
和index.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/miscHelperToolCusLib.tld"
prefix="misc"%>
<html>
<body>
<div>
<h1 class="header">Welcome <misc:username />.</h1>
</div>
</body>
<html>
我在页面上看到:Welcome .
知道出了什么问题。任何帮助表示赞赏。