I want to do something like this:
<?php echo date('Y'); ?>
But then in a .jsp file. All the tutorials I’m seeing require building a class somewhere. We’re running appFuse and Tapestry. Surely one of those (if not Java itself) provide us with something to do this sort of thing without all that overhead.
This seems like it should work, but doesn’t:
<%= new Date.getYear() %>
Use
jsp:useBeanto construct ajava.util.Dateinstance and use JSTLfmt:formatDateto format it into a human readable string using aSimpleDateFormatpattern.The old fashioned scriptlet way would be:
Note that you need to specify the full qualified class name when you don’t use
@page importdirectives, that was likely the cause of your problem. Using scriptlets is however highly discouraged since a decade.This all is demonstrated in the
[jsp]tag info page as well 🙂