Need help w. the JSTL c:out tag.

Discussion in 'Java' started by Steve Burrus, Dec 6, 2004.

  1. Steve Burrus

    Steve Burrus Guest

    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.
     
    Steve Burrus, Dec 6, 2004
    #1
    1. Advertisements

  2. Steve Burrus wrote
    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.
     
    Heiner Kücker, Dec 6, 2004
    #2
    1. Advertisements

  3. Steve Burrus

    Steve Burrus Guest

    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?
     
    Steve Burrus, Dec 6, 2004
    #3
  4. 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
     
    The Abrasive Sponge, Dec 7, 2004
    #4
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.