JavaMail, Sun's Sample App and Tomcat 4.x

Tags: Uncategorized

I recently downloaded Sun’s sample application for JavaMail. As the name implies, JavaMail is Sun’s Java API for interfacing with email systems. Using JavaMail, you can access POP or IMAP accounts, as well as send messages.

Unfortunately, Sun’s sample app does not run on Tomcat 4.x for two reasons: their WEB-INF/web.xml is malformed and their tags are not fully qualifies. Both of these issues were most likely ignored by older versions of Tomcat, but this one picky.

Remember the good-old days when it was ok to define a tag-library before defining a servlet in web.xml? Well, forget those days. Tomcat 4 wants web.xml to adhere tp the following DTD:

(icon?,display-name?,description?,distributable?,context-param*,servlet*,servlet-mapping*,session-config?,mime-mapping*,welcome-file-list?,error-page*,taglib*, resource-ref*,security-constraint*,login-config?,security-role*,env-entry*,ejb-ref*)

So, modify web.xml and places all the servlet tags first, the servlet-mapping tags second and the taglib tag last.

The next problem was harder to figure out. I was getting errors on the JSP pages, telling me that classes used for JavaMail’s custom tags weren’t being found. Basically, the JavaMail taglib JAR had classe files that weren’t in a fully qualified directory (eg. com.sun.javamail.taglib), they were at the root of the JAR. For some reason this kept Jasper from finding them and using them to compile the JSPs. Long story short, modify the following files:

messagecontent.jsp
add:
&lt;%@ page import="MessageTag" %&gt;<br/> &lt;%@ page import="MessageInfo" %&gt;<br/> &lt;%@ page import="ListAttachmentsTag" %&gt;

messageheaders.jsp
add:
&lt;%@ page import="ListMessagesTag" %&gt;<br/> &lt;%@ page import="MessageInfo" %&gt;

send.jsp
add:
&lt;%@ page import="SendTag" %&gt;

Hope that helps!

About Me

Hey there. My name is Carter Rabasa and I am a husband and father of two beautiful daughters Catherine and Emily. I live in Seattle, WA.