Friday
Oct 14, 2011
4:14 pm
Filed under Java, JSP, JSTL
Being a traditionalist, I tend to forget some of the things you can do with tag libraries like JSTL above and beyond simple things like outputting information. A colleague asked me about putting the current year on a page and my first response was something like this:
<%@ page import="java.util.*"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt"%>
<%
Date date = new java.util.Date();
pageContext.setAttribute("date", date);
%>
<c:set var="date" value="${date}" />
<fmt:formatDate pattern="yyyy" value="${date}" />
It’s quite obvious looking at it that there’s a bit of redundancy in setting the date with a scriptlet and then making it available to JSTL to output with the Format tag library. That’s when I came across the solution to use the JSP useBean tag with JSTL resulting in the much simpler solution as follows:
<%@ 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="now" class="java.util.Date" />
<fmt:formatDate var="year" value="${now}" pattern="yyyy" />
<c:out value="${year}" />
I don’t believe it has any version dependencies (as I’ve encountered with some of the JSTL libraries that only work with the JSP 2.0 spec and the like) and certainly feels cleaner. Most importantly, it gets rid of the scriptlet and, in the JSP world, that’s a win.
Comments Off
Filed under AdaLovelaceDay, AdaLovelaceDay11, Personal
This post is in honor of Ada Lovelace Day, an annual day of recognition for women in the STEM disciplines (science, technology, engineering and math) who inspire others by their example and enrich our world through their contributions.

After rediscovering my interest in astronomy and getting a membership in the , I’ve been able to start looking at the stars and sharing my hobby with my family. We even got a look at what I think was the recent supernova near the big dipper that was visible from Earth and a really good look at Venus as it’s been making its presence known last month.
I wish I had been aware of Maria Mitchell when I was young and first becoming interested in astronomy. Not only do I think a variety of role models are critical to anyone studying sciences, her words resonate today:
If for four hours a day you studied, year after year, the science of language, for instance, do you suppose you would not be a linguist? Do you put the mere pleasing of some social party, and the reception of a few compliments, against the mental development of four hours a day of study of something for which you were born?
She’s the topic of a book detailing her life and how science became to be a masculine domain from which women were excluded, Maria Mitchell and the Sexing of Science: An Astronomer Among the American Romantics. Throughout her life, she was a proponent for more women studying science, and well aware of what is lost when the ideas and inspirations of women are absent. She also pointed out the necessity of woman, as with all scientists, to ask questions and to not simply accept those in authority. “The great gain would be freedom of thought. Women, more than men, are bound by tradition and authority. What the father, the brother, the doctor, and the minister have said has been received undoubtingly. Until women throw off this reverence for authority they will not develop. When they do this, when they come to truth through their investigations, when doubt leads them to discovery, the truth which they get will be theirs, and their minds will work on and on unfettered.”
There’s plenty of information about Maria Mitchell and it’s worth reading about her life and her thoughts in her own words.
Comments Off