JSP 在 Tomcat 中无法正确呈现
我有一个在 Tomcat 中运行的 JSP 页面,该页面无法正确呈现。这是 helloworld.jsp 的样子:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="cms-taglib" prefix="cms" %>
<html>
<head>
<title>${content.title}</title>
</head>
<body>
<cms:mainBar
dialog="my-page-properties-dialog"
label="Page Properties"
adminButtonVisible="true"/>
<h1>${content.title}</h1>
<p>Hello Magnolia World !</p>
Current time: <%= new java.util.Date() %>
<%-- JSP Comment --%>
</body>
</html>
最终输出如下:
<%@页 contentType="text/html;字符集=UTF-8" 语言=“java”%> <%@标签库 uri =“cms-taglib”前缀=“cms”%>你好 玉兰世界!
你好,木兰世界!当前时间: <%= new java.util.Date() %> <%--JSP 评论--%>
简而言之,似乎只有表达式 ${content.title} 被评估并渲染得很好,但其他所有内容(如页面指令、其他 JSP 表达式和 JSP 注释)却没有。
我使用的是 Tomcat 附带的 CMS,但发行版中的 JSP 模板示例看起来不错。我想我上面写的代码有问题。
更新:我修复了日期表达式和评论的结束标记。但是,页面指令并未被解析。
I have a JSP page running in Tomcat that is not rendering properly. Here is what helloworld.jsp looks like:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="cms-taglib" prefix="cms" %>
<html>
<head>
<title>${content.title}</title>
</head>
<body>
<cms:mainBar
dialog="my-page-properties-dialog"
label="Page Properties"
adminButtonVisible="true"/>
<h1>${content.title}</h1>
<p>Hello Magnolia World !</p>
Current time: <%= new java.util.Date() %>
<%-- JSP Comment --%>
</body>
</html>
and the final output is like this:
<%@ page
contentType="text/html;charset=UTF-8"
language="java" %> <%@ taglib
uri="cms-taglib" prefix="cms" %> Hello
Magnolia World!Hello Magnolia World ! Current time:
<%= new java.util.Date() %> <%-- JSP
Comment --%>
In short, it seems like only the expression ${content.title} is evaluated and rendered fine but everything else like the page directives, other JSP expressions and JSP comments are not.
I'm using a CMS that comes with Tomcat but the JSP templates samples from the distribution seem fine. I suppose it's something wrong from the code I written above.
Update: I've fixed the closed tag for the date expression and the comment. However, the page directives aren't being parsed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为你的jsp评论有问题。
它应该如下所示。你不使用IDE来开发你的jsp吗?当出现语法错误时,您的 IDE 应该会告诉您。
I think there are problem with your jsp comment.
It should look like below. Are you not using IDE to develop your jsp? Your IDE should tell you when you have syntax error.
我发现了问题。对我来说这是一个愚蠢的错误。尽管我修复了正确的 JSP 语法并具有 jsp 扩展,但我仍需要告诉 CMS 引擎将该模板显式呈现为 JSP。感谢大家发现我的语法错误。我想在使用其他框架时需要注意这一点。
I found the problem. It's a stupid mistake on my end. Even though I fixed the correct JSP syntax and had the jsp extension, I needed to tell the CMS engine to explicitly render that one template as JSP. Thanks everyone for catching my syntax error though. I suppose it's something to watch out for when working with other frameworks.
java scriplet
<%= new java.util.Date() %
也未正确关闭(<%= new java.util.Date() %>
)加上如 gigadot 所说,<%-- JSP Comment --%
未正确关闭<%-- JSP Comment --%>
。问候,
The java scriplet
<%= new java.util.Date() %
is also not closed properly (<%= new java.util.Date() %>
) plus like gigadot stated, the<%-- JSP Comment --%
is not closed properly<%-- JSP Comment --%>
.Regards,
通常我们会看到这样的代码,当解析器无法识别文件时,浏览器中显示的代码,即文件扩展名未添加到解析器列表中。
通常tomcat在/conf文件夹下的web.xml中有此配置。
另外,如果您使用某些文本编辑器进行编码,请确保您仅使用 .jsp 扩展名进行存储,而不是意外地使用 .jsp.txt 进行存储!
Usually we see the code,displayed in browser when a file is not recognized by the parser,i.e file extension is not added to parser list.
Usually tomcat has this configuration in web.xml under /conf folder.
Also, if you are using some text editor to code, Please ensure you are storing with .jsp extension only and not .jsp.txt, accidentally !