使用自定义标记创建jsp模板时,出现以下错误:
此处不允许使用脚本元素(<%!,< jsp:declaration,<%=,< jsp:expression,<%,< jsp:scriptlet)。
我的用户详细信息标记文件:
<!DOCTYPE html>
<%@tag description="Base Template" pageEncoding="UTF-8"%>
<%@tag import="java.util.HashMap"%>
<%@tag import="com.sample.beans.common.User"%>
<%@tag import="java.util.Map" %>
<%@tag import="java.util.ArrayList"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
request.setAttribute("userDetails", userDetails);
%>
<%@attribute name="title"%>
<%@attribute name="custom_style" fragment="true"%>
<%@attribute name="body_area" fragment="true" %>
<%@attribute name="custom_script" fragment="true"%>
<html>
<head>
<title>${title}</title>
<jsp:invoke fragment="custom_style"/>
</head>
<body>
<div>
<jsp:invoke fragment="body_area"/>
</div>
<jsp:invoke fragment="custom_script"/>
</body>
</html>
我的user.jsp文件:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="t" tagdir="/WEB-INF/tags" %>
<t:userdetails title="test">
<jsp:attribute name="body_area">
<button id="who">click me</button>
</jsp:attribute>
<jsp:attribute name="custom_script">
<script>
$(document).ready(function() {
$('#who').on('click', function() {
alert(${requestScope.userdetails.username});
});
});
</script>
</jsp:attribute>
</t:userdetails>