我有这段代码
<fmt:formatDate value="<%=new java.util.Date() %>" var="now" type="both"/>
<c:out value="${now }" />
给出错误
org.apache.jasper.JasperException: Unable to compile class for JSP
现在我有了这段代码:
<c:set var="dd" value="<%=new java.util.Date() %>" />
<fmt:formatDate value="${dd}" var="now" type="both"/>
<c:out value="${now }" />
提供正确的输出:
Mar 22, 2017 10:09:24 PM
所以我的问题是这两个代码有什么不同。
编辑1: 完整代码:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
The above mentioned codes were inserted here.
</body>
</html>
答案 0 :(得分:0)
两种格式化工作都很好!我不明白你遇到问题的原因:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Format 1</h1>
<fmt:formatDate value="<%=new java.util.Date() %>" var="now" type="both"/>
<c:out value="${now }" />
<h1>Format 2</h1>
<c:set var="dd" value="<%=new java.util.Date() %>" />
<fmt:formatDate value="${dd}" var="now" type="both"/>
<c:out value="${now }" />
</body>
</html>