• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Stack Overflow Error

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your addUser method is infinitely recursive.
 
Mohammed Uddin
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A singleton is never the correct approach in a web app.
 
Mohammed Uddin
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 231
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out your code. . May be somewhere you are assigning higher privilages to lower ones. . .
 
reply
    Bookmark Topic Watch Topic
  • New Topic