aspose file tools*
The moose likes Servlets and the fly likes Stack Overflow Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Stack Overflow Error" Watch "Stack Overflow Error" New topic
Author

Stack Overflow Error

Mohammed Uddin
Ranch Hand

Joined: Mar 04, 2012
Posts: 31
Hi,

I am new to Servlets and JSP and am trying to write a simple web site where a user is able to register and then login. When I try to register I keep getting a stack overflow error.

User Class:


Customer Class:


Register JSP:


Login JSP:


Register Success JSP:


Login success jsp:


So, when I actually run my Register JSP page, fill in the form and press submit, I get the following error:
Exception in thread "http-bio-8080-exec-3" java.lang.StackOverflowError at java.util.ArrayList.<init>(Unknown Source)

I dont get any such error for my login jsp page (I am currently using dummy logic checks for the purpose of getting something up and running for the login process).

I know that a stack overflow error is caused by a call to some method or another which causes the stack to grow infinitely but as I am new to both Servlets and JSP I am unable to see where this is happening.

Can someone help me please.

Thanks,
MoSha


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

Your addUser method is infinitely recursive.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mohammed Uddin
Ranch Hand

Joined: Mar 04, 2012
Posts: 31
Hi,

Thanks alot for the quick reply.

The addUser method which I am calling is the User classes addUser method, not the Customer classes addUser method i.e. the Cusomter classes addUser method is calling the User classes addUser method.

Please see updated classes below which still produces the same error:

Register Servlet JSP:


Customer Class:


User Class:


Thanks,
MoSha
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18652
    
    8

Your "User(n, p)" constructor at line 14 is infinitely recursive.

From a design point of view, you don't seem to know whether an instance of the User class represents a single user or a list of users.
Mohammed Uddin
Ranch Hand

Joined: Mar 04, 2012
Posts: 31
Hi,

Thank you for your help. I now see how it is indeed recursive.

I am actually new to this and have never programmed Servlets or JSP's before. As opposed to making a database connection (again something I have never done before) I am trying to use a Singleton User class to try and store my customer data for now.

Thanks to all who helped.

MoSha
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

Mohammed Uddin wrote:I am trying to use a Singleton User class to try and store my customer data for now.


Eek!

You are planning to create a web site that can be used by only one person?
Mohammed Uddin
Ranch Hand

Joined: Mar 04, 2012
Posts: 31
Well, I am not actually creating a website at all. This is, as one would say, a first project to see how things work.

I am using the singleton class so that I can export all data created to a csv file and I don't want more than one instance of the same class access the same file at the same time - this singleton class is there for now until I learn how to implement some form of database connectivity, storing/retrieving information from a database - the User class is just a driver/stub class.

I will be honest, I have spent no more than a total of about 5 hours across 3 days in total learning about servlets and JSP so until I get some good grounding on this I probably should not look into database connectivity. But, this said if you know of any basic tutorials for db connectivity (JDBC I think) then do let me know.

Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

A singleton is never the correct approach in a web app.
Mohammed Uddin
Ranch Hand

Joined: Mar 04, 2012
Posts: 31
Hi,

Thank you all for your help and advice. I will most certainly take it all on board. As I have indeed found the answer to me question on this thread, I have set it to resolved.

I look forward to posting, contributing and helping others where possible.

Best regards,
Mohammed
shivam singhal
Ranch Hand

Joined: Jul 15, 2012
Posts: 226

Check out your code. . May be somewhere you are assigning higher privilages to lower ones. . .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stack Overflow Error