JSF Backbean  Init or constructer calles twise.

Hi,
Am new in JSF , I have a problem which stoped me further developments, Here is the description, Managed backbean Constucter I have Initialized a test field with random number. When the page loads Textbox initialized with new random number. When I submit , in submit button code I print the value from textbox, it shows a diffrent value as becuase Init calls twise. In short, page is initialed when loaded and again initalised when submiting that page So I lost previous random no. displyed... My question is why page initialise twise? How can I retrive previous value...? or solve this issue
Here is my test code..
public class TestBean extends AbstractPageBean {
private void _init() throws Exception {
public TestBean() {
System.out.println("Value before Assiginin.... "+getTxtValue());
setTxtValue("OT" + RandomGenerator.getRandomOrder()); /////// HERE I SET RANDOM TO TEST BOX , WHEN LOAD PAGE GENERATE ONE , AND DISPLAY ON BOX,BUT WHEN SUBMIT BUTTON, THIS CODE EXECUTE AGAIN AND A NEW RANDOM NUMBER PRINT ON SUBMIT BUTTON CODE BELOW.
System.out.println("Value after Assiginin.... "+getTxtValue());
@Override
public void init() {
try {
_init();
} catch (Exception e) {
log("TestBean Initialization Failure", e);
throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
@Override
public void preprocess() {
@Override
public void prerender() {
@Override
public void destroy() {
protected SessionBean1 getSessionBean1() {
return (SessionBean1) getBean("SessionBean1");
private String txtValue;
* @return the txtValue
public String getTxtValue() {
return txtValue;
* @param txtValue the txtValue to set
public void setTxtValue(String txtValue) {
this.txtValue = txtValue;
public String btnModify_action(){
System.out.println("Value is......"+getTxtValue()); /////////////////////////////....HERE I RECEIVE DIFFRENT VALUE
return null;
Can any body help on this , I hope I explained to you...
Thanks
Subin

Thanks, It Resolved my issue. And here is my JSP code with hidden field
<webuijsf:form id="form1">
<webuijsf:label id="label1" style="position: absolute; left: 144px; top: 144px" text="Label"/>
<webuijsf:button actionExpression="#{TestBean.btnModify_action}" id="button1"
style="left: 287px; top: 264px; position: absolute; width: 95px" text="Button"/>
<webuijsf:textField columns="50" id="textField1" readOnly="true" style="position: absolute; left: 216px; top: 144px" text="#{TestBean.txtValue}"/>
<webuijsf:hiddenField id="hiddenField1" text="#{TestBean.txtValue}"/>
</webuijsf:form>
May be helpful to others,...

Similar Messages

  • Init method is called multiple times

    Hi,
    init method in my servlet is called more than 1 time.
    I think it is supposed to be called only 1 time,when the application is loaded.
    anything to do with web.xml ???
    or else what r the situations that init method is called more than 1 time
    thanks

    Hi,
    actually I figured out the problem.
    I am using logger staements for debugging.
    I am also using singlethread model for servlet.
    I came to know that it creates multiple instances of servlet...
    which inturn calls init method multiple times.
    i took out that singlethread model,now it is working perfect.
    Thanks

  • When the init mehtod is called

    When the init mehtod is called?
    while running the server or by running the servlet program.
    When u create a enterprice project in WSAD you will have JavaResource and Web Content in your project.
    Say i have 10 servlet program in my JavaResource.
    When running the JavaResource by right cliking and run on this server which servlet will run first and when will the init method is called.
    ** (I am using Websphere)**_

    If you have gone thorugh the servlet life cycle methods, you could have come to know when init method is called.
    Servlet�s life cycle is controlled by the container in which the servlet has been deployed. When a request is mapped to a servlet, the container performs the following steps. If an instance of the servlet does not exist, the Web container
    a.     Loads the servlet class.
    b.     Creates an instance of the servlet class.
    c.     Initializes the servlet instance by calling the init method. Initialization is covered in Initializing a Servlet. 2.     Invokes the service method, passing a request and response object.
    If the container needs to remove the servlet, it finalizes the servlet by calling the servlet's destroy method.
    I think now you can understand when init method is called.

  • JavaBean: init(Ihandler) not called!

    Hello all!
    I've developped some JavaBeans with success so far. Now I want to implement custom events: receiving events from the Bean as events in the Forms-application. So I developped everything according to the samples, but IHandler allways is null:
    getHandler() delivers null
    and
    init(...) is never called?
    What can be wrong? Any experiences?
    Thank you for any answer!
    Regards,
    RR

    Hello Frank! A good idea!
    Here are some details (I've left away some lines, which are not necessary to know):
    ===== java bean: EditBean.class ====
    /* Short Information: mHandler1 and mHandler2 are printed out with value null */
    package test;
    import java.awt.AWTEvent;
    import java.io.*;
    import java.util.*;
    import java.awt.event.MouseListener;
    import oracle.forms.handler.IHandler;
    import oracle.forms.properties.ID;
    import oracle.forms.ui.VBean;
    import oracle.forms.ui.mdi.MDIContainer;
    import oracle.forms.ui.CustomEvent;
    import oracle.forms.engine.*;
    import oracle.forms.handler.*;
    import java.applet.*;
    import java.beans.*;
    import java.awt.*;
    import java.awt.event.*;
    public class EditBean extends VBean implements MouseListener
    private TextField tf;
    private Component mComp;
    private static final ID MOUSECLICKED=ID.registerProperty("MouseClicked");
    private static final ID MOUSEPRESSED=ID.registerProperty("MousePressed");
    private IHandler mHandler1=getHandler();
    public void init(IHandler handler) {
    super.init(handler);
    System.out.println("init: Handler "+handler);
    mHandler2=handler;
    private void init_event(Component obj) {
    System.out.println("init event: Handler "+mHandler2);
    mComp=obj;
    mComp.addMouseListener(this);
    public boolean setProperty(ID pid,Object value) {
    return super.setProperty(pid,value);
    public void mouseClicked(MouseEvent event) {
    System.out.println("mouseClicked: Beginn");
    CustomEvent ce=new CustomEvent(mHandler,MOUSECLICKED);
    System.out.println("mouseClicked: nach custom");
    dispatchCustomEvent(ce);
    System.out.println("mouseClicked: nach dispatch");
    /* Constructor */
    public EditBean()
    System.out.println("EDITBEAN construct handler="+mHandler1);
    try
    jbInit();
    catch(Exception e)
    e.printStackTrace();
    private void jbInit() throws Exception
    this.setSize(620,230);
    this.setLayout(borderLayout1);
    tf=new TextField();
    init_event((Component)tf);
    ===== Forms: WHEN-NEW-FORM-INSTANCE ===
    declare
         hbean item:=find_item('buttons.beanarea');
         args fbean.arglist:=fbean.create_arglist();
    begin
         Fbean.register_bean(hbean,1,'atpeds.EditBean');
         Fbean.enable_event(hbean,1,'MouseListener',true);
    end;
    ===== Forms: WHEN-BUTTON-PRESSED ===
    declare
         hbean item:=find_item('buttons.beanarea');
         args fbean.arglist:=fbean.create_arglist();
    begin
    fbean.add_arg(args,-1);
    fbean.Invoke(hbean,1,'someMethod',args);
    fbean.clear_arglist(args);
    end;
    =====
    The Form and the bean are shown correctly. The "Invoke"s work ok. But, as I mentioned above, the handler always show null in JInitiator's Console window.
    Thank you for any answer,
    RR

  • Backing file init method always called for proxy portlets

    Hello,
    We are currently using Weblogic Portal 10 MP1. Deployed within our Portal EAR is a local proxy portlet and attached to this proxy portlet is a backing file, which currently implements the init() and prerender() methods from the backing interface.
    When this is placed in a page that is within a desktop, the init() method is always invoked no matter which page you access within the desktop. As I understand it from the documentation, if you have "tree optimization" turned on, then the init() method will only be called when rendering the actual page the proxy portlet is in. But this doesn't seem to be the case. However, if I define a standard Java portlet within the EAR and attach a backing file, then the init() follows the rules when tree optimization is turned on or off.
    Does anyone know if this is a defect within the portal framework, or is this expected and proxy portlets do not follow this rule?
    And I guess, if it is a defect or known limitation, is there a possible workaround? I assume the simplest workaround will be to move the logic into the prerender() method.
    Regards,
    Jonathan

    Hello Jonathan,
    Tree optimization is a tricky thing- some portlets may still be initialized even when the page they are on isn't visible. The rules for which get initialized and which don't are very complicated and depend on a number of things, so it is just best to not rely on the init() method not getting called.
    By far the best option for your use-case is to have the proxy portlet listen to the "onRefresh" event, and move the logic from the backing file's init() method into an event-handling method in the backing file, then have this method called when the refresh event is received. Here's a sample portion of the .portlet file for doing this:
    <netuix:handlePortalEvent event="onRefresh" eventLabel="onRefreshEvent">
        <netuix:invokeBackingFileMethod method="handleRefreshEvent"/>
    </netuix:handlePortalEvent>The "onRefresh" event is sent to the portlet only when it is visible on the page, so it should work perfectly for your use-case.
    Kevin

  • Putting code to my Jsf and Jsff pages and calling Java class

    I want guidance on how to write simple code on adf pages
    1. I have adf pages (.jsf and .jsff) where I have input text fields and command buttons, I want to put custom code on the command button such that when you click on any of the buttons at runtime, the code will be executed.
    2. In my application, I have a java class which I have written, I need to click on any of the buttons at runtime, the application will call the java class and execute the class. Essentially, taking parameters from my adf page(s) (.jsf and .jsff) to the java class and also returning parameters after execution.

    The version of my Jdev. is 11.1.2.3.0
    Which docs?.... I will be grateful if you can point to the particular doc fro me.
    1) Can you pls tell me in one of few sentences how to add method and set the actionListener property.
    2) in question number 2, I am totally lost... Let me explain my self again to clarify the situation. In my adf page, I have a button and three input texts,my purpose is that at runtime, when a user click on the button, the values in the first two input texts will be passed to the java class as parameters, it is expected to use these parameters to process some form of calculations and return a value which I will place on the  third input field.

  • JSF 2 @ViewScoped doesn't call @PreDestroy method

    howdy guys!
    i've been tested the jsf ViewScoped in my application but i have a doubt. The managed bean noted with @ViewScoped sometimes does not call the @PreDestroy method.
    See example below
    ViewScopeMB.java
    @ManagedBean
    @ViewScoped
    public class ViewScopeMB implements Serializable {
    private int counter;
    public ViewScopeMB() { }
    @PostConstruct
    public void contruct() {
    System.out.println("iniciando bean");
    this.counter = 0;
    // getters and setters
    public void increment() {
    System.out.println("incrementing...");
    this.counter++;
    public void forceSetView() {
    System.out.println("modificando a viewroot");
    FacesContext context = FacesContext.getCurrentInstance();
    UIViewRoot root = context.getApplication().getViewHandler().createView(context, "/faces/one.xhtml");
    context.setViewRoot(root);
    @PreDestroy
    public void destroy() {
    System.out.println("destroy the bean");
    I'm using f:ajax to incrementing the counter and this work fine, the bean instance is kept, but when i navigate for new page using <a:href for exemple the ViewScopeMB instance is not destroyed. I change my link to <h:commandLink action="rule"... and the @PreDestroy method is called and the finalize method too.
    My question is, this is a correct behavior of JSF 2? If the user use the navigator back button or to type the new url or the button with javascript history.go(-1) my instance of ViewScopeMB will never be destroyed in the user session?
    When i used forceSetView() method to force a new viewRoot the @PreDestroy is called.
    There are way to solve this case?
    Sorry if i not been very clear.
    Anybody help-me?

    For a view scoped bean, PreDestroy must only be called when the view scope is destroyed which happens when something calls FacesContext.setViewRoot(root).
    It's not very surprising that when you don't use JSF controls for navigation then context.setViewRoot(root);is not called.
    Calling context.setViewRoot(root); yourself guarantees that PreDestroy gets called but you'll probably end up calling it more times than you need to in the cases where you use JSF navigation mechanisms.
    You should be careful with that @PreDestroy method though. Some containers e.g (Tomcat) don't always support those methods fully. In particular, @PreDestroy methods are not called when the view gets destroyed after a restart when the webserver had serialized the ViewScoped bean in the current view so I wouldn't be putting billion dollars worth of logic in that method.

  • Why is a superclass constructer called automatically?

    I have two simple classes as shown:
    public class Class1 {
    public Class1() {
    System.out.println("Hello World");
    public class Class2 extends Class1 {
    public Class2() {
    static public void main(String[] args) {
    Class2 c2 = new Class2();
    When I run Class2 (i.e. java Class2) it prints out "Hello World". It looks as though the constructor for class 2 is automatically calling the constructor from its superclass (class 1). I thought that you had to specify this with super(). Any Advice?

    this should be in new to java programming.
    anyway, the constructor of the super class need to be call automatically so that the object is in the proper state. suppose you extends from JFrame with class call MyJFrame. when you create your MyJFrame the code that construct the JFrame must be automatically called so that it works fine, after the constructor of the super class get called to initialize it's data then your subclass can initialize its own data. the constructor that is called automatically is the no-argument constructor. so if your super class does not have no-argument constructor you must explicitly call the appropiate super constructor in your subclass. also you cannot create instance of subclass that extends from the super class that has only private no-argument constructor.

  • Call doGet in the Init of a servlet?

    Hello
    Please could you show through the code. I think there is something wrong with the init. If I run the servlet, it don't show a thing. It only displays: Site can't not be shown.
    The doGet and also the dopost is not executed. Must I call in the doPost in the init(). And when yes how?
    Thanks a lot!
    Sandra Frei
    import java.sql.*;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.Properties;
    public class update42 extends HttpServlet {
         Connection con = null;
         public void init() {//throws ServletException {
              String url = "jdbc:DBF:/sys:copal/copal_data/data/gesch/data/stamm";      
              try {
                   //Register the JDBC driver
                   Class.forName("zyh.sql.dbf.DBFDriver");//.newInstance();
                   con = DriverManager.getConnection(url, "fre","sandy66");                    
              catch( Exception e ) {
                   e.printStackTrace();
              }//end catch
         }//end init()
         public void doGet(HttpServletRequest req, HttpServletResponse res)
              throws ServletException, IOException {
              res.setContentType("text/html");
              PrintWriter out = res.getWriter();
              out.print("in do get");
              //connecting to the Database
              Statement stmt = null;
              ResultSet rs = null;
              PreparedStatement ps = null;
                   try
                   stmt = con.createStatement();
                   catch (SQLException e) {e.getNextException();}                              
                   // displaying records
                   try
                   rs = stmt.executeQuery("SELECT Random, Nsa, Bzng, Bzn2, Tart, Meeh, Fstat, Nzn FROM part");
                   catch (SQLException e) {e.getNextException();}                              
                   try
                   while(rs.next()) {
                        out.print("<form action=\"");
                        out.print( req.getRequestURI() );
                        out.print("\" method=\"post\">");
                        out.print("<input type=\"text\""); //hidden
                        out.print(" name=\"Random\" size=\"15\" value=\"");//without 15
                        out.print( rs.getObject(1).toString() );
                        out.print("\">");
                        out.print("<input type=\"text\"");
                        out.print(" name=\"Nsa\" size=\"15\" value=\"");
                        out.print( rs.getObject(2).toString() );
                        out.print("\">");
                        out.print("<input type=\"text\"");
                        out.print(" name=\"Bzng\" size=\"25\" value=\"");
                        out.print( rs.getObject(3).toString() );
                        out.print("\">");
                        out.print("<input type=\"text\"");
                        out.print(" name=\"Bzn2\" size=\"25\" value=\"");
                        out.print( rs.getObject(4).toString() );
                        out.print("\">");
                        out.print("<input type=\"text\"");
                        out.print(" name=\"Tart\" size=\"6\" value=\"");
                        out.print( rs.getObject(5).toString() );
                        out.print("\">");
                        out.print("<input type=\"text\"");
                        out.print(" name=\"Meeh\" size=\"6\" value=\"");
                        out.print( rs.getObject(6).toString() );
                        out.print("\">");
                        out.print("<input type=\"text\"");
                        out.print(" name=\"Fstat\" size=\"6\" value=\"");
                        out.print( rs.getObject(7).toString() );
                        out.print("\">");
                        out.print("<input type=\"text\"");
                        out.print(" name=\"Nzn\" size=\"15\" value=\"");
                        out.print( rs.getObject(8).toString() );
                        out.print("\">");
                        out.print(" <input type=\"submit\"");
                        out.print(" value=\" \">");
                        out.print(" Update<br>");
                        out.print("</form>");
                   catch (SQLException e) {e.getNextException();}                              
                   try
                        if(rs != null)
                             rs.close();
                        if(stmt != null)
                             stmt.close();
                   catch (SQLException e) {
                        e.printStackTrace();
         out.print("</pre></code>");
         out.print("<p\"><a href=\"");
         out.print( req.getRequestURI() );
         out.print("\">Back</a></p>");
         out.print("</body></html>");
         out.close();
         public void doPost(HttpServletRequest req, HttpServletResponse res)
              throws ServletException, IOException {
              res.setContentType("text/html");
              PrintWriter out = res.getWriter();
              out.print("<html><body>");
              out.print("<code><pre>");
              out.print("<table border=1>");
         out.print("<tr>");
              out.print("<td><font color=green>Artikelnr</font></td>");
              out.print("<td><font color=green>Bezeichnung</font></td>");
              out.print("<td><font color=green>Zusatzbezeichnung</font></td>");
              out.print("<td><font color=green>Art</font></td>");
              out.print("<td><font color=green>ME</font></td>");
              out.print("<td><font color=green>Stat</font></td>");
              out.print("<td><font color=green>Spezifikation</font></td>");
         out.print("</tr>");
              // receiving parameters
              String Bzn2 = req.getParameter("Bzn2").trim();
              String Meeh= req.getParameter("Meeh").trim();
              String Pk = req.getParameter("Random").trim();
              boolean proceed = false;
              Statement stmt = null;
              Statement stmt1 = null;
              ResultSet rs = null;
              try {
                   String sql;
              sql = "UPDATE part SET Bzn2 = " + "'" + Bzn2 + "'" + " WHERE Random LIKE " + "'" + Pk + "'";
                   stmt1 = con.createStatement();               
                   out.print(sql);
                   out.print(Bzn2 + Meeh + Pk);
                   stmt1.executeUpdate(sql);
              // displaying records
                   stmt = con.createStatement();               
                   rs = stmt.executeQuery("SELECT * FROM part");
                   while(rs.next())
                        out.print("<tr>");
                        out.print("<td>"+ rs.getObject(1).toString()+ "</td>");
                        out.print("<td>"+ rs.getObject(2).toString()+ "</td>");
                        out.print("<td>"+ rs.getObject(3).toString()+ "</td>");
                        out.print("<td>"+ rs.getObject(4).toString()+ "</td>");
                        out.print("<td>"+ rs.getObject(5).toString()+ "</td>");
                        out.print("<td>"+ rs.getObject(6).toString()+ "</td>");
                        out.print("<td>"+ rs.getObject(7).toString()+ "</td>");
                        out.print("</tr>");
                   out.print("</table>");
              catch (Exception e)     
                   out.print(e.getMessage());
                   e.printStackTrace();
                   try
                        if(rs != null)
                             rs.close();
                        if(stmt != null)
                             stmt.close();
                        if(stmt1 != null)
                             stmt1.close();
                   catch (SQLException e) {e.getNextException();}
              out.print("</pre></code>");
              out.print("<p\"><a href=\"");
              out.print( req.getRequestURI() );
              out.print("\">Back</a></p>");
              out.print("</body></html>");
              out.close();
         public void destroy() {
              try {
                   //Close the connection to the database
                   con.close();
              } catch( Exception e ) {
                   e.printStackTrace();
    }

    It won't get shown unless you make a call to the servlet from (e.g.) a web browser referencing it. And no - don't call doPost() or doGet() from the init() method. You might be lucky, and it might work, but it's inherently unsafe. Servlet engines will not normally call these methods until the servlet is properly initialised.
    And BTW, there is no guarantee that init() will be called until the first call to the servlet, unless you specify load on startup to the servlet engine.
    Your best bet is simply to type the URL of your servlet into your web browser. That will call doGet(). To call doPost(), you'll have to write a little HTML page with a form with method="post" and action=the name of your servlet.
    Robin

  • Servlet init() method called multiple times

    We have a Servlet-based application which does lengthy initialization.
    We've noticed that when multiple requests arrive,
    but the Servlet's init() method has not returned yet
    for the first request, the application server calls init() multiple times.
    You can even see this with the Fortune sample
    Servlet. Starting the app server and sending 20 or 30
    simultaneous requests causes multiple Fortune Servlet init messages to appear in the kjs log.
    Why is this? We do not implement SingleThreadModel.
    Doesn't the J2EE 1.2 spec say init will be called
    only once?
    How do we prevent it?
    A Startup class which inits our
    Servlet?
    Or a synchronized block within our init method, with some checks of static member variables
    so that the initialization work only happens once?
    Or is there some kregedit magic or deployment descriptor change I could make?
    Again, it's not a SingleThreadModel issue, so don't
    point me there.
    This is iAS 6.0 SP4, on Solaris, by the way.

    Hi
    Yes,you are right. In iAS6.0 SP4 When multiple requests arrive,and the Servlet's init() method has not returned yet for the first request, the application server calls init()multiple times. This problem is resolved in iAS 6.5.
    There is no kregedit magic that will solve this problem.
    Right now the workaround is any of the solution you proposed. Or use iAS6.5. I have tested it with fortune.
    Please download it and check with your application.
    you can find free download at http://developer.iplanet.com/appserver/testdrive/testdrive_65.html
    Thanks

  • Why Do We Have To Call super.init(config); in init() method of servlet?

    Hi, everyone..
    I wonder why we call super.init(config) in init method of servlet... If i dont call it ; when i try to get servletcontext in service method it throws java.lang.NullPointerException...when we call super.init() , what is happening behind the scene? If anybody has a technical explanation for my question , i will be very pleased...
    THX FOR YOUR FUTURE REPLIES IN ADVANCE....

    I am sorry about the uppercases and i dont want to seem smart on java forums... Anyway, m8 this is the thing that i know... i meant; for instance when we override doGet or doPost method ; we dont need to override init method; but the server loads the servlet and we can get the context of the servlet in these methods easily by calling getServletContext() method; however when we want to call service method implicitly by jndi, servlet needs to be loaded and init method must call its parent...(i also write down in web.xml <load-on-startup>.... for that servlet).
    thx for your replies in advance....

  • Init() called twice??

    Hi all,
    I have a simple dummy servlet, and when I set it up with "load-on-startup" = 1, the init() method is called twice by different threads! I've logged the thread's getName() to stdout. This is what I see:
    (main) init........
    (http-8084-Processor8) destroying........
    (http-8084-Processor8) init........I'm using tomcat 5.5 bundled with netbeans 4.1.
    Here is the servlet code and the relevant web.xml part:
    web.xml:
      <servlet>
        <servlet-name>myservlet</servlet-name>
        <servlet-class>servlet2.myservlet</servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>myservlet</servlet-name>
        <url-pattern>/myservlet</url-pattern>
      </servlet-mapping>
    myservlet.java:
    public class myservlet extends HttpServlet {
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {}
        public void destroy() {
            System.out.println(Thread.currentThread().getName() + " destroying........");
            super.destroy();
        public void init() throws ServletException {
            System.out.println(Thread.currentThread().getName() + " init........");
            super.init();
    }

    All,
    IDE: Eclipse 3.3
    Environment: J2EE 1.3
    Server: Tomcat 6
    I had a similar problem and found via other postings that it was due to the following:
    - Had my context setting in my Tomcat6/conf/server.xml file
    - Had default context setting in my Tomcat6/conf/context.xml
    This was causing 2 startups of my servlet in Tomcat6/conf/web.xml file
    I moved my context from Tomcat6/conf/server.xml to Tomcat6/conf/context.xml
    and got only 1 init() println from my Servlet.
    Hope that helps someone.
    - JFK

  • Why does SunOne 6.1 call servlet init() method twice on startup

    Hi,
    SunOne6.1 sp 5 is running my servlet's init() method twice when I put load-on-startup in the web-xml file. Is this a known problem and is there a work around as no amount of synchronising seems to work.
    I'm running 2.3.dtd for the default_web.xml file and my entries look like this :-
    <servlet>
    <servlet-name>RelatisLogin</servlet-name>
    <servlet-class>com.MyServlet</servlet-class>
    <load-on-startup>7</load-on-startup>
    </servlet>
    This init method only contains a basic check at the moment :-
    public void init()
    System.out.println("init.....");
    If I take <load-on-startup> away and run the server then call the servlet via the url it only runs init once.
    I've tried synchronizing the block but this doesn't work.
    The synchonization code I used looks like this:-
    public void init(ServletConfig config) throws ServletException
    synchronized( AnotherClass.staticString )
    if ( AnotherClass.staticString.length() > 0 ) return;
    System.out.println( AnotherClass.staticString.length() );
    AnotherClass.staticString = "init has been called";
    try
    int i = 0;
    i = i/i;
    } catch(Exception e)
    e.printStackTrace();
    The declaration of "AnotherClass.staticString" is :-
    public static String staticString = "";
    The output of "System.out.println( AnotherClass.staticString.length() );" is 0 and displayed twice.
    I deliberately cause a divide by zero error to get a stack trace so that i can determine what called init(), the stack trace is printed twice and is always :-
    java.lang.ArithmeticException: / by zero
    at com.MyServlet.init(MyServlet.java:47)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:921)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:813)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3478)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:3760)
    at com.iplanet.ias.web.WebModule.start(WebModule.java:251)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1133)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:652)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1133)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:355)
    at org.apache.catalina.startup.Embedded.start(Embedded.java:995)
    at com.iplanet.ias.web.WebContainer.start(WebContainer.java:431)
    at com.iplanet.ias.web.WebContainer.startInstance(WebContainer.java:500)
    at com.iplanet.ias.server.J2EERunner.confPostInit(J2EERunner.java:161)
    It looks like SunOne starts then calls init() and then restarts and calls init() again.
    The same code and same web.xml entries work fine in Tomcat 5, init() only every gets called once.
    Any ideas? Can I post this as a bug?
    Thanks in advance for any help.
    Chris.

    Sorry to have not replied to this thread earlier.....forgot all about it.
    The reason init was being called twice by IPanet (Sun One) is IPanet comes with a default context called "Search" already in server.xml file.
    This context was loading all the classes on my class path and this causing "init" to run. Then my context entry also loaded all the files in the class path.
    Quite why Sun include this "Search" context is beyond me......annoying. If you take it out the the problem goes away.
    Basically if you leave this in then your running to web servers (JVM's) your one and Sun's stupid "Search" one. As they are separate JVM's no amount of synchronisation would ever fix it.

  • Multpile inits being called in Servlet

    I am trying to create one thread which will be executed once Jakarta-Tomcat begins execution. To do this I have the following code:
    web.xml
      <servlet>
        <servlet-name>initializecontroller</servlet-name>
        <servlet-class>roverlook.InitializeController</servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>     
    InitializeController.java
    public class InitializeController extends HttpServlet {
      public void init(ServletConfig config) throws ServletException {
        super.init(config);
        Daemon.INSTANCE.start(); // start daemon thread
    Daemon.java
    public class Daemon extends Thread{
      public static final Daemon INSTANCE = new Daemon(null); // singleton
      public synchronized void run  () {
         while(true) {
            LoggerCentral.info("Daemon executing required jobs at "+ (new java.util.Date()).toString(), null);
            // do work here
            try {
           Thread.sleep(1000*60);       
            } catch (InterruptedException e) {
                LoggerCentral.exception("Daemon:run():sleep interrupted", null);
        }         When I run Jakarta-Tomcat, I can see the Daemon writing once every ~1 minute as expected. However, when I run other Servlets (which aren't related to this) there are additional instances of the Daemon which are apparently created, because I see many writes to the logfile, sometimes only 1 second apart. It seems like the init() function is being called again even though I t should not be.
    To simplify things, I just put a System.out.print() statement in init() and it is in fact called multiple times! Putting a similar statement reveals that destroy() is not being called.
    I'm confused, because I thought init() was supposed to run once - Can anyone help out?
    Thanks alot

    Thank you for the good suggestion - I think I was able to make some progress. The first init() is called in
            at roverlook.InitializeController.init(InitializeController.java:37)
            at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:918)
            at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:243)which looks like normal initialization to me. The second one is:
            at roverlook.InitializeController.init(InitializeController.java:37)
            at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:918)
            ....     org.apache.catalina.connector.warp.WarpConfigurationHandler.deploy(WarpConfigurationHandler.java:313)
            at org.apache.catalina.connector.warp.WarpConfigurationHandler.handle(WarpConfigurationHandler.java:117)
            at org.apache.catalina.connector.warp.WarpConnection.run(WarpConnection.java:189)
            at java.lang.Thread.run(Thread.java:536)which makes me think it has to do with the fact that I am using Apache Tomcat as a front end and using the Warp connector. In my httpd.conf file I have the following:
    WebAppDeploy roverlook warpConnection /roverlook/
    WebAppDeploy roverlook warpConnection /roverlook/jsp/*.jspIt would appear that this warp connector is causing init() to be called more than once! (could it be in a different JVM?). I need things which are accessed via the connector to share the same space with things in tomcat that load via 'load-on-startup'.
    Any additional suggestions? Thanks.

  • How to get iPhone app to call init on my class?

    I have just a standard view application. The projects hac (project)AppDelegate.h and m files when I created it. I then added two more classes, BundleViewer and BundleBrowser.
    When the application is launched, I need BundleViewer's init to be called (in order for it to initialize the instance variables).
    I am obviously missing a step or overlooking a config or something.
    Put another way, i have a text field. When the user is done entering text with the keyboard, it's IBAction is called. In that IBAction method, I need to operated on an instance of a class, but this instance is never initialized because the init method (in the same class as said IBAction) is never called. Thus nothing works and I play frizbee with this macbook air, which sounds great after a day of sitting in this office. RAWR!

    If you created a view based application, you should also see <app name>ViewController sources. In the implementation file, you uncomment the viewDidLoad method and then do what you need.

Maybe you are looking for

  • Don't get timecode via firewire from FCP to Panasonic HVX200A for DV.

    When I try to 'print to video' or just play the timeline for a NTSC DV sequence, I get video and audio on my Panasonic HVX200A camera, but no timecode. The timecode display on the camera doesn't move and when I 'Log and Capture' the video that I just

  • Tidal vs Powershell

    Hi, Visited this one before with limited success but now its time to try again. Platform is TES 6.1.0.212 running on Solaris x86, CM is on RH linux, agent on windows server 2003. I'm attempting to automate some MS excel work via powershell. I have a

  • Mac doesn't reads external hard disk

    Hello, I am using Mac OS X 10.9.3 Mavericks and from a few days i am facing an issue that my mac mini late 2012 model doesnt reads my external hard disks, it reads my pendrives. The light on the hard disk glows, it appers in the disk utility but it i

  • Photoshop Raw plug-in version update?

    When I go to open photoshop 14.2.1 x64 on my Mac laptop, a window ask edit with lightroom rederings, then says that i need a photoshop RAW plug in version 8.4 for full compatibility. Where do I find that? not in updates tool as suggested.

  • Macbook never shuts down

    I have a Macbook 2,1 running 10.6.8 that is fully updated (system updater can't find any new updates) Whenever I put my computer on sleep, the DVD drives constantly makes the noise it does when it wakes up (DVD laser moving back and forth, every 10 s