我有一个使用标签模板的页面。 我的web.xml非常基础。JSP标签+ scriptlet。如何启用scriptlet?
我只是想在页面中运行一些代码。
不,我对标签或其他选择不感兴趣。我想使用坏习惯scriptlet哈哈。
到目前为止,我得到这个 “HTTP错误500” 错误:
Scripting elements (%!, jsp:declaration, %=, jsp:expression, %, jsp:scriptlet) are disallowed here.
虽然我的文件看起来像:
/WEB-INF/web.xml
<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
/WEB-INF/tags/wrapper.tag
<%@tag description="Simple Wrapper Tag" pageEncoding="UTF-8"%>
<%@ attribute name="title" required="true" type="java.lang.String"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>${title}</title>
</head>
<body>
<jsp:doBody />
</body>
</html>
的index.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="t" tagdir="/WEB-INF/tags"%>
<t:wrapper>
<jsp:attribute name="title">My nice title</jsp:attribute>
<jsp:body>
<h1><%="some code generated text"%></h1>
</jsp:body>
</t:wrapper>
我试图修改web.xml中明确地启用它,像这样(没有工作):所以
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<scripting-invalid>false</scripting-invalid>
</jsp-property-group>
<jsp-property-group>
<url-pattern>*.tag</url-pattern>
<scripting-invalid>false</scripting-invalid>
</jsp-property-group>
</jsp-config>
,我怎么用我的标签中的纯小脚本” ed JSP?
编辑#1:
理想的代码是这样的,使用我的模板( '包装' 同上)一个页面内:
<%@page import="java.util.Calendar"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="t" tagdir="/WEB-INF/tags"%>
<t:wrapper>
<jsp:attribute name="title">My nice title</jsp:attribute>
<%
final int day_of_week = Calendar.getInstance().get(
Calendar.DAY_OF_WEEK);
if (day_of_week == Calendar.SATURDAY)
{
%>
<jsp:body>
<h1>Have a nice Saturday (<%=Integer.toString(day_of_week)%>)!</h1>
</jsp:body>
<%
}
else
{
%>
<jsp:body>
<h1>Have a nice rest-of-the-week (<%=Integer.toString(day_of_week)%>)!</h1>
</jsp:body>
<%
}
%>
</t:wrapper>
看到了吗? ''标签内的&之间的Scriptlets。这正是我想要实现的。
这是在本地版本?您要部署哪个servlet容器?这听起来像是一个主web.xml不允许这样做,但需要更多的信息来帮助! – Codemwnci
它在Google App Engine上(它们使用Jetty AFAIK)dev(本地)服务器。 – Poni