threebit.NET General EJB Tutorial
[threebit.net] [tutorial home]

Introduction

This is not a tutorial as much as a quick collection of notes I've picked up while starting out on my first EJB/JBoss/Tomcat/Struts/Postgres/XDoclet project. I hope you find it usefull; if your reading this you probabaly got here from a search engine so I wish you luck.

If you have any comments or questions, please direct them to the Threebit general mailing list (general@lists.threebit.net)

Before we start, a quick intro to my configuration:

Exceptions, Errors and Bears - Oh My!

<html:form>, ActionMappings and ActionForms. This one took me a few days to figure out. When using the <html:form> tag, either JBoss or Tomcat will not create / parse the struts-config.xml document until *after* a post to the ActionServlet. Now that I'm typing this out it makes total sense but I still wasted a few days on it nonetheless.

If you are getting the Cannot find ActionMappings or ActionFormBeans collection exception when accessing a JSP page, manually make a request to the ActionServlet. Most example code suggests this URL would be something like

http://localhost/your_web_app/action/blah
http://localhost/your_web_app/some/nested/url/your_action.do

You don't need to send this manual request to a real Action - so long as the container maps the request to the ActionServlet you're OK. In my environment I simply use an Ant <get> task to hit

http://localhost:8080/my_web_app/action/dumbHackToAvoidThisProblemSmileyFace

Also, anytime the web application is reloaded this procedure needs to be repeated.

Doh!. After all that, I just learnt that all you need to do is direct the servlet container to load the servlet on startup by adding a <load-on-startup>5</load-on-startup> directive to the <servlet> section in web.xml.

org.apache.jasper.JasperException: Cannot find ActionMappings or ActionFormBeans collection
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:248)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
Resource Bundles. So, you've played with Struts and everything is working nicely. Like a regular developer you left resource bundles till the end. But, now you want to use <html:errors>, but when you do you get:
javax.servlet.ServletException: Cannot find message resources under key org.apache.struts.action.MESSAGE
        at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:530)
        at org.apache.jsp.createCustomer_jsp._jspService(createCustomer_jsp.java:126)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:204)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:432)
You'll need to create your Resource bundle. A fact I had to track down was how do you tell Struts where your resource bundle is? It's one of the servlet initialization parameters in web.xml.
<servlet>
  <servlet-name>credux</servlet-name>
  <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
  <init-param>
    <param-name>application</param-name>
    <param-value>net.threebit.credux.struts.CreduxResources</param-value>
  </init-param>
</servlet>