0

I have a JSP file starts a TimerTask on the server. Everytime that the server is restarted, The TimerTask object is lost and I have to manually hit the JSP page to set it again. By any chance, can I add a server script that hits the JSP page automatically just after the server has been restarted?

Note: Its a JBOSS 3.2.8 server

simpleJack
  • 344
  • 1
  • 3
  • 11
  • JBoss start != Webapp start! Do you mean when the Webapp starts? – Grim Jan 21 '13 at 12:15
  • Invokation of jsp depends on requests. Requests usually depends on inet-interfaces (or you like to mock them?). If you dont mock them you need to specify the concrete inet-interface. – Grim Jan 21 '13 at 12:18

1 Answers1

1

Pull the code from JSP, place it in a servlet and define a servlet to be initiated automatically in web.xml.

<servlet>
    <servlet-name>myServlet</servlet-name>
    <servlet-class>com.class.MyServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

(Servlet can forward to the same JSP so that requests could still get that JSP)

eis
  • 51,991
  • 13
  • 150
  • 199
  • Is there any way by which I can check if the class is already loaded? I followed your method, but my server loads it several times. Don't know why.. – simpleJack Jan 21 '13 at 12:21
  • you'll need to check if you have some other conf referring to the same servlet, or if your code within the servlet is correct. init() method of the servlet should be called only once. doGet() gets called every time there's a request. you could include some logic within the servlet to check if the code has been already run (servlets have only one instance) – eis Jan 21 '13 at 12:43