Category Archives: Java

JasperException: Failed to load or instantiate TagExtraInfo

org.apache.jasper.JasperException: Failed to load or instantiate TagExtraInfo class

(I had to shorten the article title to fit!)

I’ve just had a problem when I’ve taken a web application from my local Tomcat 5.5 development server (where it worked fine) and uploaded it onto a public server (also using Tomcat 5.5).

Continue reading JasperException: Failed to load or instantiate TagExtraInfo

Following symbolic links in Tomcat

We have several web applications derived from the same code base and as well as sharing the jars in WEB-INF/lib, we provide set of administration pages to allow users to configure and administer the applications. Until now, we’ve always had to make copies of the admin pages and this has caused us configuration headaches as we try and make sure that all the applications have the latest versions of all the pages.

But now I’ve finally managed to work out how to make Tomcat follow symbolic links—and it’s very easy! Continue reading Following symbolic links in Tomcat

Groovy, DSLs and Rules engines

This article describes how we used Groovy to create a DSL for the clauses in a rules engine. We have been collaborating in the development of an “expert system” application for KnowledgeBench Ltd. This application uses a forward chaining rules engine to provide a “smart” system capable of creating formulations in domains such as pharmaceutical tablet formulation, inhalers, paints, food & drink and cosmetics. Continue reading Groovy, DSLs and Rules engines

JNDI problems with Tomcat 5.5.15

I’ve recently been having difficulty getting JNDI lookup for MySQL connection pools working on our public server.

This proved very difficult to track down as all the stuff that I could find on the web said that I had to have:

  • commons-dbcp-1.2.1.jar
  • commons-pool-1.2.jar
  • mysql-connector-java-3.1.6-bin.jar

(or the latest appropriate versions)

Unfortunately this didn’t work and my little test JSP (using the JSTL sql tags) just gave me the error: DataSource invalid:
“java.sql.SQLException: No suitable driver.

However, next I tried connecting to MySQL directly using Class.forName(""com.mysql.jdbc.Driver") and that worked. So the problem wasn’t in loading the driver. Continue reading JNDI problems with Tomcat 5.5.15

Outputting stack traces in a JSP using JSTL

If you’re writing a JSP using the JSTL tag <c:catch var=”myError”> … </c:catch> then I’m sure that you know that the next thing to do is to check after the closing catch tag to see if myError is empty. If not you can output some useful error message having successfully caught any exception. However, sometimes it’s useful to actually output the stack trace (when debugging a site for example). It turns out not to be difficult to do this. Simply copy in the following:

<c:if test="${not empty myError}">
<p class="error">An error occured: <c:out value="${myError}"/></p>
<pre>
<c:forEach var="stackTraceElem" items="${myError.stackTrace}">
<c:out value="${stackTraceElem}"/><br/>
</c:forEach>

UTF-8 with Hibernate 3.0 and MySQL

Hi again, I’m now tackling something I’ve been meaning to do for ages (and probably should have done before I started the project) and that is to use Hibernate rather than rolling my own SQL.

I’m reading the book “Hibernate in Action” by Christian Bauer and Gavin King and have been trying it out. The book relates to Hibernate 2.0 and 2.1 so doesn’t include annotations which is a bit of a shame, but it’s still a good start.

Unfortunately as readers of this blog will know, I’m trying to put UTF-8 strings into the database so you can imagine my disappointment when I saw the familiar question marks appearing where there should be interesting new characters.

The fix turned out to be not so difficult to find however, thanks to Philip Whirlycott’s blog posting More UTF-8 head-thumping with Hibernate 3 (obviously I’m not the only one struggling with these issues).

With Hibernate 3 (maybe not with 2.1, I’m not sure), you need to add some extra connection parameters:

jdbc:mysql://localhost/mydb?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8

If you put this in your hibernate.cfg.xml file for the JDBC URL it works and you can save the UTF-8 correctly.

UTF-8 subjects in javax.mail

I’ve been having problems with putting unicode strings into the subject of emails sent using javax.mail.

In the end, the solution was very simple and I found it here:

http://www.velocityreviews.com/forums/t132009-utf8-characters-not-appearing-correctly-in-email-subject-line.html

As long as you use “UTF-8” and not “UTF8” it all seems to work fine, so the code you need is:

Properties props = new Properties();
// put in your SMTP host in here
props.put("mail.smtp.host", "localhost");
Session s = Session.getInstance(props, null);

MimeMessage message = new MimeMessage(s);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject(subject, "UTF-8");
message.setText(body, "UTF-8");
message.setHeader("Content-Type", "text/plain; charset=UTF-8");
Transport.send(message);

Internationalisation again

Further to my post about creating properties files when I had text files in unicode, we decided that the best thing was to have a web application to do the conversion. You can then just paste in whatever text you want to encode and it tells you what the java escaped text string(s) should be.

And, we decided we might as well make it publicly available. So here it is.

Let us know if you find any bugs or if you can think of a better way to do it :-)