Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting HTTP 500- javax.servlet.ServletException: BeanUtils.populate

 
Rimzim Basu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

This is my first post so I apologize for breaking any rules.

I get this exception "javax.servlet.ServletException: BeanUtils.populate" error when I leave the page open for a while (around 30 mins) and then click on the 'Submit' button on my page. I have seen a couple of posts on Indexing here on CodeRanch and I went through them, trying to understand and implement, but nothing seems to be helping. Here is the error screenshot:




FORM (PhaseTrackerForm.java):




FORM (PhaseTrackerSelectApprInfo):





JSP Code:




struts-config.xml mapping:




I did understand indexing getter setter but 'selectApprList' is the id for <logic:iterate> and an array of type PhaseTrackerSelectApprInfo. I read that array type is supposed to work but I get the error anyway.

I'm really confused because I've been breaking my head over what I'm missing. Any help is appreciated.
 
Joe Ess
Bartender
Posts: 9376
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rimzim Basu wrote:
I get this exception "javax.servlet.ServletException: BeanUtils.populate" error when I leave the page open for a while (around 30 mins) and then click on the 'Submit' button on my page.


Does it work if you click "submit" promptly?  If so, it sounds like your session is timing out and Struts is relying on some session information to rebuild the list.  You can control the session timeout by adding a session-timeout declaration to your application's web.xml:

 
Rimzim Basu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joe,

Thanks a lot for replying.

If I click on 'Submit' promptly, it works absolutely fine. Earlier the session timeout value was 30. I had changed it to -1 and it seems to be working fine even after an hour. But, will this not cause the sessions to keep piling up? I am not very clear on this. Also, the users that we mostly deal with seem to leave the page open and come back later to resume what they were doing. Is there a way I can handle this without this error showing up? It's pretty old code so any design change would be big. So looking for other options as well.

Thanks,
Rimzim
 
Rimzim Basu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe Ess wrote:
Rimzim Basu wrote:
I get this exception "javax.servlet.ServletException: BeanUtils.populate" error when I leave the page open for a while (around 30 mins) and then click on the 'Submit' button on my page.


Does it work if you click "submit" promptly?  If so, it sounds like your session is timing out and Struts is relying on some session information to rebuild the list.  You can control the session timeout by adding a session-timeout declaration to your application's web.xml:




Hi Joe,

Thanks a lot for replying.

If I click on 'Submit' promptly, it works absolutely fine. Earlier the session timeout value was 30. I had changed it to -1 and it seems to be working fine even after an hour. But, will this not cause the sessions to keep piling up? I am not very clear on this. Also, the users that we mostly deal with seem to leave the page open and come back later to resume what they were doing. Is there a way I can handle this without this error showing up? It's pretty old code so any design change would be big. So looking for other options as well.

Thanks,
Rimzim
 
Joe Ess
Bartender
Posts: 9376
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rimzim Basu wrote:[ But, will this not cause the sessions to keep piling up?


Yes. You will have to watch your server and make sure you have enough resources to handle them.  Depending on your server, the session may be stored in memory, on disk, in a DB, or some other option.

Rimzim Basu wrote:the users that we mostly deal with seem to leave the page open and come back later to resume what they were doing.


You should have some sort of timeout implemented see here.  You need to balance the needs of your users against the resources available to your server.

Rimzim Basu wrote:
Is there a way I can handle this without this error showing up? It's pretty old code so any design change would be big. So looking for other options as well.


This appears to be a known issue with Struts 1.  I assume that's what you are using.  Struts 1 has other problems too: see here.
 
Rimzim Basu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe Ess wrote:
Rimzim Basu wrote:[ But, will this not cause the sessions to keep piling up?


Yes. You will have to watch your server and make sure you have enough resources to handle them.  Depending on your server, the session may be stored in memory, on disk, in a DB, or some other option.

Rimzim Basu wrote:the users that we mostly deal with seem to leave the page open and come back later to resume what they were doing.


You should have some sort of timeout implemented see here.  You need to balance the needs of your users against the resources available to your server.

Rimzim Basu wrote:
Is there a way I can handle this without this error showing up? It's pretty old code so any design change would be big. So looking for other options as well.


This appears to be a known issue with Struts 1.  I assume that's what you are using.  Struts 1 has other problems too: see here.



I believe I can use something like this in the action class:


        HttpSession session = request.getSession(false);
        if (session != null) session.invalidate();
        return mapping.findForward("success");


But, where am I to include this? Should it be after the submit? Again, I'm missing out on that part. I mean, should this be implementing this if I keep session timeout as -1?

Thanks,
Rimzim
 
Joe Ess
Bartender
Posts: 9376
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rimzim Basu wrote:
I believe I can use something like this in the action class:

        HttpSession session = request.getSession(false);
        if (session != null) session.invalidate();
        return mapping.findForward("success");

But, where am I to include this?


What are you trying to accomplish?  This code would terminate any existing session, so any user who hits this action would be logged out.

Rimzim Basu wrote:
I mean, should this be implementing this if I keep session timeout as -1?


That depends on what you are trying to accomplish. As I said previously, the "best practice" is to have an automatic session timeout.  How is security implemented?  I would assume that anyone who's session has expired should be forwarded to the login page rather than allowed to continue into an action.
 
Rimzim Basu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


That depends on what you are trying to accomplish. As I said previously, the "best practice" is to have an automatic session timeout.  How is security implemented?  I would assume that anyone who's session has expired should be forwarded to the login page rather than allowed to continue into an action.


I'm sorry, Joe. I'm fairly new to development so I'm still learning so my questions would seem quite silly. I was thinking if I out -1 as the session timeout, I'll have to invalidate the sessions manually. Also, I tried checking if the session is null just after I enter the submit method in Action class so that I can redirect it to the home page but somehow it doesn't enter this method at all when I click on 'Submit' and the error comes
 
Joe Ess
Bartender
Posts: 9376
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rimzim Basu wrote:I'm fairly new to development so I'm still learning so my questions would seem quite silly


No worries. We all had to start somewhere.

Rimzim Basu wrote: I was thinking if I out -1 as the session timeout, I'll have to invalidate the sessions manually. 


The server will not invalidate them.  It's up to you to determine if this is desired functionality or not.  This code would make sense in a "logout" action.

Rimzim Basu wrote:
Also, I tried checking if the session is null just after I enter the submit method in Action class so that I can redirect it to the home page but somehow it doesn't enter this method at all when I click on 'Submit' and the error comes


You can see from the stack trace that the exception occurs when Struts is trying to reconstruct the List, so it occurs before your action has control.
Struts builds on "regular" JEE functionality, so we usually use JEE security.  There are some alternatives, like Spring Security, but JEE security is built into the server.  You can start with the Introduction to Security chapter of the JEE tutorial.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!