From: Isabel M. <ism...@ma...> - 2005-01-27 03:03:32
|
Ian, Thanks for your help. Pardon my limited knowledge about servlets, which package do I import so I can use ServletContext? I cannot compile my java bean without the appropriate import statement and I can't seem to find the right package. Thanks, Isabel ----- Original Message ----- From: Ian Roberts <i.r...@dc...> Date: Wednesday, January 26, 2005 12:43 pm Subject: Re: Running Gate 3.0 with Tomcat 5.0 > On Wednesday 26 Jan 2005 16:32, Isabel Moyo wrote: > > Thanks for pointing me to the User Guide, I had no idea there were > > instructions for configuring Tomcat. I'm not sure about the > "Initializing> code" section of the User Guide and how it relates > to my web application. I > > am using JSP and Java Beans. I have StandAloneAnnie setup as a > Java Bean > > with JSP pages calling its methods. Do I have to extend > GenericServlet as > > shown in the Initialization code of the User Guide? If not > please let me > > know how to initialize Gate from within a java bean. > > You could put the initialization code into a static method of your > bean: > public class ANNIEBean { > private static boolean gateInited = false; > > public static void init(ServletContext ctx) throws > ServletException, > IOException { > if(!gateInited) { > Gate.setGateHome( > new File(ctx.getRealPath("/WEB-INF"))); > Gate.setPluginsHome( > new File(ctx.getRealPath("/WEB-INF/gate-plugins"))); > Gate.setSiteConfigFile( > new File(ctx.getRealPath("/WEB-INF/site-gate.xml"))); > Gate.setUserConfigFile( > new File(ctx.getRealPath("/WEB-INF/user-gate.xml"))); > > Gate.init(); > // load plugins > Gate.getCreoleRegister().registerDirectories( > ctx.getResource("/WEB-INF/gate-plugins/ANNIE")); > > gateInited = true; > } > } > > // other methods go here..., initAnnie, execute, etc. > } > > Then at the top of each JSP page, put > <% ANNIEBean.init(application); %> > > This will ensure that GATE is initialized by the time you want to > use it (and > the init() method shown above will only initialize GATE if this > hasn't > already been done). > > There is one important caveat worth mentioning: GATE processing > resources are > *not* thread safe - bad things will happen if you allow two > concurrent > requests to use the same instance of the ANNIE > SerialAnalyserController. An > easy way to get around this initially is to make initAnnie(), > execute() etc. > synchronized methods, but you will need to jump through a few more > hoops if > you need to be able to handle concurrent requests. > > Ian > > -- > Ian Roberts | Department of Computer Science > i.r...@dc... | University of Sheffield, UK > |