Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Cycles of Servlets  RSS feed

 
Joe Wolf
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm very new to Java so I'm not sure what goes on with the programs I "copy" but now I am writing a servlet with a doPost() method that prints out HTML. In this HTML is a <form> with an action that calls the same servlet again.
Would this approach spawn multiple instances of my Servlet class? I'd rather have one instance of a class with content that gets modified based on user HTML input. What would be the best way to do that?
 
imb4u2cu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should generate a HTML output in doGet method..and for Form's METHOD=POST ACTION="Your_Same_Servlet_Name.
Now u can get the response in the same servlet.
Sorry i didnt understand ur second part of the question.
------------------
I am before you to see you!!!
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't store user info in the servlet's class - on a heavily-used system you'd have thousands of instances sitting around mostly idle. For short-term storage, use sessions. For longer-term storage storage, write it out to a file or database and load as needed.
I think you're suffering from the common misconception that a servlet is a client-server type program that you log into and run. It's not. Like all http servers, it's transaction-oriented.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!