我试图通过eclipse在tomcat7上创建简单的项目。 这是我的jsp页面的代码:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
User ID: ${user.userId}<br />
Username: ${user.username} (${user.username.length()} characters)<br />
Full Name: ${fn:escapeXml(user.lastName) += ', '
+= fn:escapeXml(user.firstName)}
<br /><br />
<b>Permissions (${fn:length(user.permissions)})</b><br />
User: ${user.permissions["user"]}<br />
Moderator: ${user.permissions["moderator"]}<br />
Administrator: ${user.permissions["admin"]}<br />
</body>
</html>
以下是浏览器窗口的结果:
org.apache.jasper.JasperException: javax.el.ELException: Failed to parse the expression [${fn:escapeXml(user.lastName) += ', '
+= fn:escapeXml(user.firstName)}]
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
ProfileServlet.doGet(ProfileServlet.java:46)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
root cause
javax.el.ELException: Failed to parse the expression [${fn:escapeXml(user.lastName) += ', '
+= fn:escapeXml(user.firstName)}]
org.apache.el.lang.ExpressionBuilder.createNodeInternal(ExpressionBuilder.java:145)
org.apache.el.lang.ExpressionBuilder.build(ExpressionBuilder.java:171)
org.apache.el.lang.ExpressionBuilder.createValueExpression(ExpressionBuilder.java:216)
org.apache.el.ExpressionFactoryImpl.createValueExpression(ExpressionFactoryImpl.java:66)
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:943)
org.apache.jsp.WEB_002dINF.jsp.view.profile_jsp._jspService(profile_jsp.java:96)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
ProfileServlet.doGet(ProfileServlet.java:46)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
root cause
org.apache.el.parser.ParseException: Encountered " <ILLEGAL_CHARACTER> "= "" at line 1, column 32.
设置了目标运行时(tomcat7)。 我的tomcat7 / lib目录可能有问题吗? (jstl 1.2 jar在文件夹中)
这里也是从base.jspf(这是所有JSP的标题)的导入
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
&#34;定期&#34; jstl标签运行良好。功能问题
答案 0 :(得分:2)
尝试使用core:out
,如下所示:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
User ID: <c:out value="${user.userId}" />
<br /> Username: <c:out value="${user.username}" /> (<c:out value="${user.username.length}" /> characters)
<br /> Full Name: <c:out value="${user.lastName}" />, <c:out value="${user.firstName}" />
<br />
<br />
<b>Permissions (${fn:length(user.permissions)})</b>
<br /> User: <c:out value="${user.permissions.user}" />
<br /> Moderator: <c:out value="${user.permissions.moderator}" />
<br /> Administrator: <c:out value="${user.permissions.admin}" />
<br />
</body>
</html>
它对我来说很好,默认情况下它会转义为XML。