Question re jspInit() and EJB initialization

Posted on 2004-10-22
Last Modified: 2012-08-13

What is the purpose of jspinit() and what must you use it and when do you not need it.  Must an entity bean be initialized inside the jspinit() or not, if the EJB is to be used in the jsp?  Thanks.
Question by:skip1000
    LVL 8

    Accepted Solution

    jspInit basically is the method which the servlet container calls when starting the JSP first time when a request comes for it. this is called only once for the whole lifecycle. you can have some of the initialization code which u might need for all your subsequent requests. like looking up ur EJB/DataSource. If you dont have any requirement for resources common across requests then u dont do anything, just have ur plain jsp code.

    for knowing how to write the code for looking up and jspInit check this out
    LVL 8

    Expert Comment

    Its always better to have a Session bean as a wrapper for your Entity bean access becoz of Transactions, performance,  security.....

    also check out this link for a tutorial
    LVL 13

    Expert Comment

    Hi skip,

    jspInit() is used for application parameters initialization it is called once first time u call ur JSP, like reading JSP configuration parameters, in ur case calling entity no don't lookup home in jspInit, call it normally from ur jsp body


    ur code to lookup EJB and call


    as u further go on learning J2EE u will learn that according to J2EE Blueprints JSP is not the place to call business Logic u have to use MVC (Model View Control) and its newer version Model2 frameworks like Jakarta Struts open source Model 2 framework

    to look in struts refer to:

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Suggested Solutions

    Title # Comments Views Activity
    JSP + json + data structure 10 368
    How to set default webapp for host 6 35
    Can't access image with tomcat/html 6 65
    maven j2ee examles 2 38
    Ransomware continues to be a growing problem for both personal and business users alike and Antivirus companies are still struggling to find a reliable way to protect you from this dangerous threat.
    Skype is a P2P (Peer to Peer) instant messaging and VOIP (Voice over IP) service – as well as a whole lot more.
    This video discusses moving either the default database or any database to a new volume.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    877 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now