Merrill
Consultant, Sima Solutions
Originally posted by Merrill Higginson:
I'd suggest you make the entry to your application something like Default.do. Then have this action check to see if the resources you need are already in the application context and if If they aren't, put them there. It can then forward to default.jsp, and all your resources should be properly initialized.
Merrill
Consultant, Sima Solutions
Originally posted by Merrill Higginson:
Andrew,
I'm a little unclear about what your question is at this point. In your original question, you asked someone to point out "what I should be doing". In answer to that, I gave you the recognized Struts best practice, which is to always (or nearly always) call an action, rather than calling a jsp directly, and have the action redirect to the jsp. This way, the action can set up the resources the jsp needs.
While you certainly can call one jsp from another, either in the form of a link, or even specifying it in the action attribute of the form, this is not the best practice in Struts.
As to why your original plugin didn't work, I don't know. If you put initialization logic in a class that implements the org.apache.struts.action.PlugIn interface and reference it with a <plug-in> tag in the struts-config.xml, it's init method will get called by the Struts ActionServlet when it initializes. If you are trying to access a datasource that you have defined in struts, it may not work putting the logic here, because the struts ActionServlet may not have initialized the dataSource yet. However, if you just do a JNDI lookup and find the datasource yourself, it should work.
If I'm still not answering your question, please rephrase it or elaborate to give me a better opportunity to understand it.
Merrill
Consultant, Sima Solutions
A good workman is known by his tools.
Originally posted by Merrill Higginson:
Andrew,
Thanks for the clarification. I think I understand what is happening now. I'm a bit surprised that the plugin didn't do it's work until the first action was called. It was my understanding that the struts ActionServlet calls your plugin when it performs it's init() method. Normally, the ActionServlet is configured to load on startup. This is something you might check. See if you can find:
<load-on-startup>1</load-on-startup> as a child tag of the <servlet> tag that defines the action servlet in your web.xml file.
If this still doesn't work, you have the option of creating a new servlet with your logic placed in the init method. Then register this servlet with the load-on-startup option set on.
Regarding your question about ways within struts to tell whether you have needed resources or not, I'd look a the <logic:xxx> tags, particularly logic resent/notPresent and logic:empty/notEmpty.
Good luck.
eat bricks! HA! And here's another one! And a tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|