This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I want to execute a jsp code automatically whenever the server is started. I tried with implementing the jsp file as a jar file and deployed in tomcat server but it doesn't start that program to run. Do i get any help regarding this. Thanks in advance.
No, jsp doesn't take it to any other page . It will just execute some set of instructions in the code. Making you clear about the concept, In a case some set of things to be executed automatically at the time of deployment in server ( in other words When server is started this set of codes will be executed at back end) It doesn't take it to any page. I had made this jsp codes as a jar file and implemented in the library but when deployed in server this code doesn't affect.
Seetharaman Venkatasamy wrote:I am posting this for just to know[bad to implement it in your project]
Yes, that really is bad practice, and you should not do this. A context listener is the right way to go about this; load-at-startup servlets, too, should not be used.
Tim Moores wrote: load-at-startup servlets, too, should not be used.
Tim, Please can you explain me why we should not use load-on-startup?
Tim Moores
Rancher
Joined: Sep 21, 2011
Posts: 2407
posted
0
Let me clarify: load-at-startup servlets should not be used for initialization. if their purpose is to warm up a servlet before use, that's fine, although few servlets should have such noticeable init work that it can't be suffered by even just the very first request.
But historically, load-at-startup servlets originate from a time when there were no context listeners, and they were used for init work - it's a hack to use an HTTP processor if there is no HTTP request, servlets just like JSPs.
Actually, the first - and biggest - mistake was the use of the fatal words "JSP code". JSPs should not contain code. Put the code in a Java class.
Customer surveys are for companies who didn't pay proper attention to begin with.
Saurabh Pillai
Ranch Hand
Joined: Sep 12, 2008
Posts: 449
posted
0
Sabi Swa wrote: I tried with implementing the jsp file as a jar file and deployed in tomcat server but it doesn't start that program to run.
How do you implement this? and what makes you think that it should or shouldn't work? Also, when you say it does not work, are you getting any error? Just saying it does not work, does not help much.
Also, I would be interested, what exactly you want to get done when server starts? There may be some better way to get it done.
Tim Moores
Rancher
Joined: Sep 21, 2011
Posts: 2407
posted
0
The better ways have already been suggested several times by now. Trying to get a JSP solution to work for this is a waste of time.
Indeed. The proper way to do this is with a context listener. Using a JSP for this is using a hammer to bang in a screw, and using a servlet is an old trick that is no longer necessary.