File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes How to execute a function from servlet on JSP start up Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "How to execute a function from servlet on JSP start up" Watch "How to execute a function from servlet on JSP start up" New topic
Author

How to execute a function from servlet on JSP start up

dekij ra
Ranch Hand

Joined: May 21, 2010
Posts: 37
Hello, I have a function inside my servlet that populates a JSP form on start up (on load). The thing that puzzles me is that it works most of the time, however once in a while it doesn't. When the JSP loads, there is no data being populated inside the form. Please note that I am not making any changes to the code during this....so it cannot be due to code changes. After serveral restarts of the server (inside Eclipse) I can get it to work again and populate the form on JSP load like it should. Below is my servlet



This is my JSP form - like I said, it works but once in a while it just doesn't populate...no idea what might be going on


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61316
    
  66

Have you checked to make sure that the list is always getting a value? No value, means no display.

And, in the following:
What's the point of the being and end? If you only want the first element in the list, you can do without the needless for loop. In fact, I'd say don't send a list to the JSP in the first place unless you need the whole thing.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
dekij ra
Ranch Hand

Joined: May 21, 2010
Posts: 37
Yes, I put a simple System.out.println message inside the if(!people.isEmpty()) block and it executes on start up (however no data is being populated). So there must be a value for list that is loaded on start up....

Yes, I got rid of the begin and end in the loop..thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61316
    
  66

What do you mean by "on startup"?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61316
    
  66

dekij ra wrote:however no data is being populated...

So, there's the problem. No data means no display. Why is this surprising?
dekij ra
Ranch Hand

Joined: May 21, 2010
Posts: 37
But that's the thing, there is data in the DB. And it works - but once in a while it doesn't. And i don't to anything differently. I just run the JSP, once it works (data populates), the second time i run it doesn't...I have no idea what's going on
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61316
    
  66

You still have not answered my question regarding what you mean by "on startup".

So you are saying that sometimes, the call to sp.getAllPeople returns something, and sometimes it doesn't?
dekij ra
Ranch Hand

Joined: May 21, 2010
Posts: 37
What I mean by "on start up" is as soon as you run the JSP by doing "Run As -> Run On Server"....


That is exactly what I am saying. I just ran it now, and the data populated in the JSP form just fine. Then I closed the page and did run on server again, and this time I got an empty form.....am I going insane, what is going on. Could it be something with cache?? Is this the correct method to populate a form on JSP on start up, am I doing it wrong??
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61316
    
  66

dekij ra wrote:What I mean by "on start up" is as soon as you run the JSP by doing "Run As -> Run On Server"....

That has no meaning outside of the particular IDE that you are using. It's not useful and doesn't answer my question. "on startup" usually means when the web application is started. So you really mean whenever the JSP is displayed. Correct?

That is exactly what I am saying.

In that case, the problem is clearly not associated with any of the code that you have shown and is a problem with how the method that retrieves the information is operating.
dekij ra
Ranch Hand

Joined: May 21, 2010
Posts: 37
Well, yes, when the JSP starts basically. So you mean to say that it might be a problem with Eclipse IDE?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61316
    
  66

dekij ra wrote:So you mean to say that it might be a problem with Eclipse IDE?

No, I'm saying that telling people what you are doing in an IDE is not useful information for those that don't use that same IDE. Also, it means that you are using incorrect terminology. "At startup" doesn't mean "when the JSP displays". That's very confusing and I have changed the subject accordingly.

WHat I am saying is that this isn't a JSP issue, and the problem lies in code that you haven't shown.
 
GeeCON Prague 2014
 
subject: How to execute a function from servlet on JSP start up