Need help w. the JSTL c:out tag.

S

Steve Burrus

I need help w. the JSTL c:eek:ut tag!! I am just simply trying to get the
current date printed out in a JSP page, but it won't show/display! All
that it shows in the web browser is the <h2></h2> heading and then under
that this : ${date}, instead of the date that I would like to see. Here
is the code for this file :

<%-- use the 'taglib' directive to make the JSTL 1.1 core tags
available --%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%-- use the 'jsp:useBean' standard action to make the Date object
available in page scope --%>
<jsp:useBean id="date" class="java.util.Date" />
<html>
<head><title>First JSP</title></head>
<body>
<h2>Here is today's date</h2>
<c:eek:ut value="${date}" />
</body>
</html>

Thanx in advance to anyone who can help me with this problem.
 
H

Heiner Kücker

Steve Burrus wrote
I need help w. the JSTL c:eek:ut tag!! I am just simply trying to get the
current date printed out in a JSP page, but it won't show/display! All
that it shows in the web browser is the <h2></h2> heading and then under
that this : ${date}, instead of the date that I would like to see. Here
is the code for this file :

<%-- use the 'taglib' directive to make the JSTL 1.1 core tags
available --%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%-- use the 'jsp:useBean' standard action to make the Date object
available in page scope --%>
<jsp:useBean id="date" class="java.util.Date" />
<html>
<head><title>First JSP</title></head>
<body>
<h2>Here is today's date</h2>
<c:eek:ut value="${date}" />
</body>
</html>

Thanx in advance to anyone who can help me with this problem.

The java.util.Date class is no bean (has no get and set methods).
Wrap your Date in a bean class with get and set methods.
 
S

Steve Burrus

I hate to "betray" my ignorance of what you told/instructed me to do,exactly do I go about doing that anyway??! I really haven't had much
experience with working with the JSTL in a JSP file, i.e., all of the
various jstl tags like the "<c:eek:ut>" and the others. So how do I "wrap"
the Date in a bean class to where the final result will be the display
of the time/date in my browser?
 
T

The Abrasive Sponge

Steve said:
I need help w. the JSTL c:eek:ut tag!! I am just simply trying to get the
current date printed out in a JSP page, but it won't show/display! All
that it shows in the web browser is the <h2></h2> heading and then under
that this : ${date}, instead of the date that I would like to see. Here
is the code for this file :

<%-- use the 'taglib' directive to make the JSTL 1.1 core tags
available --%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%-- use the 'jsp:useBean' standard action to make the Date object
available in page scope --%>

<html>
<head><title>First JSP</title></head>
<body>
<h2>Here is today's date</h2>
<c:eek:ut value="${date}" />
</body>
</html>

Thanx in advance to anyone who can help me with this problem.

Use the formatDate in JSTL....here are some examples of how to use it.
Take a look at the documentation for more info.


<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<jsp:useBean id="date" class="java.util.Date" />
<fmt:formatDate value="${date}" pattern="EEEE, MMMM d, yyyy"/>
<fmt:formatDate value="${date}" type="date" dateStyle="short"/>
<fmt:formatDate value="${date}" type="both" dateStyle="short"
timeStyle="long"/>

Docs can be found at:
http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/fmt/formatDate.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top