apachetiles 2 和 JSP 的问题
我正在尝试让tiles 2 与JSP 一起工作。我遇到空指针异常。我无法找到解释如何进行设置的良好文档。我有一个非常简单的用例。我有一个带有名为“内容”属性的模板。然后,我尝试通过将 jsp 插入“content”属性来使用该模板。我不确定是否需要在 web.xml 文件中设置任何内容?我已经粘贴了我的模板和尝试使用该模板的 jsp。
这是模板:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://tiles.apache.org/tags-tiles" prefix="template" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/jquery-ui-1.8.5.custom.css" type="text/css" />
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/app.css" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js" type="text/javascript"></script>
<title>Cheetah Home</title>
</head>
<body>
<div id="wrapper">
<jsp:include page="${pageContext.request.contextPath}/jsp/layout/top.jsp"></jsp:include>
<template:insertAttribute name="content"></template:insertAttribute>
</div>
</body>
</html>
这是一个尝试使用该模板的页面:
<%@taglib uri="http://tiles.apache.org/tags-tiles" prefix="template" %>
<template:insertTemplate template="/templates/homeTemplate.jsp">
<template:putAttribute name="content" value="test.jsp">
</template:putAttribute>
</template:insertTemplate>
我正在使用 Maven 来构建应用程序,并且指定了以下依赖项:
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-servlet</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-template</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>2.2.2</version>
</dependency>
一切都构建得很好,但是当我运行应用程序时,我得到:
javax.servlet.ServletException: com.sun.jersey.api.container.ContainerException: org.apache.jasper.JasperException: java.lang.NullPointerException
任何人都有任何想法如何让它发挥作用?
谢谢!
I'm trying to get tiles 2 working with JSP. I'm getting a null pointer exception. I'm having trouble finding good documentation that explains how to get setup. I have a pretty easy use case. I have a template with an attribute called "content". I'm then trying to use the template by inserting a jsp into the "content" attribute. I'm not sure if I need to set anything up in my web.xml file? I've pasted my template and the jsp that is trying to use the template.
Here is the template:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://tiles.apache.org/tags-tiles" prefix="template" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/jquery-ui-1.8.5.custom.css" type="text/css" />
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/app.css" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js" type="text/javascript"></script>
<title>Cheetah Home</title>
</head>
<body>
<div id="wrapper">
<jsp:include page="${pageContext.request.contextPath}/jsp/layout/top.jsp"></jsp:include>
<template:insertAttribute name="content"></template:insertAttribute>
</div>
</body>
</html>
Here is a page trying to use the template:
<%@taglib uri="http://tiles.apache.org/tags-tiles" prefix="template" %>
<template:insertTemplate template="/templates/homeTemplate.jsp">
<template:putAttribute name="content" value="test.jsp">
</template:putAttribute>
</template:insertTemplate>
I'm using Maven to build the application, and I have the following dependencies specified:
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-servlet</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-template</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>2.2.2</version>
</dependency>
Everything builds fine, but when I run the application I get:
javax.servlet.ServletException: com.sun.jersey.api.container.ContainerException: org.apache.jasper.JasperException: java.lang.NullPointerException
Anyone have any ideas on how to get this working?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须执行一些配置才能使 Tiles 2 正常工作。文档 (http://tiles.apache.org/tutorial/configuration.html) 说您可以配置 web.xml 以包含启动 servlet、侦听器或过滤器。我尝试了监听器,但它对我不起作用。然而,过滤器做到了。
我遇到的另一个问题是您需要指定 SLF4J 实现,例如 Log4J。另请注意,当您为图块添加 Maven 依赖项时,它将为您获取 SLF4J api。您需要确保您在 Maven 中指定的实现与作为依赖项为您添加的 API 版本相匹配,否则,如果不这样做,您将遇到一些有趣的错误。
There is some configuration you must do to get Tiles 2 to work. The documentation (http://tiles.apache.org/tutorial/configuration.html) says you can configure web.xml to contain a startup servlet, a listener or a filter. I tried the listener and it did not work for me. However, the filter did.
Another problem that I ran into is that you need to specify an SLF4J implementation such as Log4J. Also be careful that when you add maven dependencies for tiles, that it will get the SLF4J api for you. You need to ensure that the implementation you specify in maven matches the version of the API that tiles added for you as a dependency, or you will run into some funny errors if you don't.
我遇到了同样的错误,但只能通过指定 SLF4J 实现来解决。 Servlet 对我有用。
I get the same error, but it solved only by specifying an SLF4J implementation. Servlet works for me.