?
Solved

JSP/Servlet app design question

Posted on 2004-11-30
5
Medium Priority
?
296 Views
Last Modified: 2012-08-13
I have a project consisting of several JSP pages and JavaBeans. There is a login front-end and DB accesses. Also, an app properties file is read in and put in a static global class for access from several pages/beans.

Q: I'm looking for a way to start the entire project up when the web server is started, including reading in the properties file and making the DB connection, BEFORE the first client logs in. The JSP pages will be precompiled into CLASS files. The beans will be given application scope.

The product may be installed on any of the popular web servers (Websphere, Weblogic, Tomcat, etc.), so the solution must be generic.

Is this possible?

PS - If a solution exists, I will increase the point value of this question for more details.
0
Comment
Question by:snazzyrags
  • 3
  • 2
5 Comments
 
LVL 8

Expert Comment

by:kiranhk
ID: 12710504
for reading the properties file, making db connection etc you can have a servlet which loads on startup of your web application and then in the init method does all these and puts whatever java beans you want into Application context so that all the jsp/servlets can access...

for precompiling your jsp's before it is accessed here is something from www.jguru.com

http://jguru.com/faq/view.jsp?EID=425278

Yes, there is a common solution that it's defined in the JSP specification and it has to be implemented by any container that claim to be compliant.
JSP 1.1 Specification paragraph 3.4.2 states:

    A request to a JSP page that has a request parameter with name "jsp_precompile" is a precompilation request. The "jsp_precompile" parameter may have no value, or may have values "true" or "false". In all cases, the request should not be delivered to the JSP page.
    The intention of the precompilation request is that of a hint to the JSP container to precompile the JSP page into its JSP page implementation class. The hint is conveyed by given the parameter the value "true" or no value, but note that the request can be just ignored in all cases.

Moved to paragraph 8.4.2 in JSP 1.2 PDF 2 Specification

So, to precompile 'myPage.jsp' it's enough to use 'myPage.jsp?jsp_precompile'.
This feature is extremely interesting even for verifying the code inside a page that requires parameters, or that contains code like sql insert or delete queries, etc.


In addition, many container have specific solution, some of them already covered by FAQs:
Tomcat with a comment regarding Oracle or JRun.
0
 

Author Comment

by:snazzyrags
ID: 12715614
Your first paragraph answered my question. There is a way to execute a servlet when the server starts up, independent of a client logging in. So, I write the servlet. How do I tell the server to run it and persist the access beans at the application level (scope) for use by the clients when they logon?

Also, I have clent statistics and other data to be written to a file when the client's session ends. How do I determine when this takes place? Do I need to create another session level servlet for each client, then put this "clean-up" code in the destroy() method?

I've increased the points in anticipation of your answer.

Thanks.
0
 
LVL 8

Accepted Solution

by:
kiranhk earned 1000 total points
ID: 12717370

you can specify the servlet to startup in the web.xml file...
  <servlet>
    <servlet-name>Startup Servlet</servlet-name>
    <servlet-class>
your servlet class
    </servlet-class>
    <load-on-startup> 1 </load-on-startup>
  </servlet>


for you session level requirement you need to have a HttpSession Listener and then do the operations when the session is started or ended..
check out the following for the sample code for Session listener....

http://java.sun.com/developer/EJTechTips/2003/tt0626.html
0
 

Author Comment

by:snazzyrags
ID: 12718343
kiranhk,

Thank you VERY much! You got me pointed in the right direction, I think I can carry it from here.

I figured there was a way to implement a listener on the session object, hadn't found it yet.
When I got your response, I was looking at the <servlet> element of the web.xml. So, I guess I was stumbling around in the right direction, but you put the light on my path.

Thanks.
0
 
LVL 8

Expert Comment

by:kiranhk
ID: 12718528
YW... Glad to be of help :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Moore’s Law has proven itself time and time again since it was first introduced. So what’s next? Will Moore’s law continue to remain relevant, or will new technology take over and bring us the next big advancement in computing?
LinkedIn blogging is great for networking, building up an audience, and expanding your influence as well. However, if you want to achieve these results, you need to work really hard to make your post worth liking and sharing. Here are 4 tips that ca…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question