• 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

Newbie here tyrint o understand Servlets

 
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

Am a newbie to Servlets.. so please bear with me. I am using WSAD IDE

I wrote the following code in a Servlet named LoginServlet



This does not work as of now.But, if I copy paste everything into the doGet() method instead of the doPost(), it works fine. Is it because by default a doGet() method is called and thats why the above code should be in the doGet() instead of the doPost() method as this is the first Servlet?

Thanks.
 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you do not specify anything in your form element for the method that you want the call to be, then doGet is called by default.
 
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes..by default doGet() method is taken by HTML and if you want to overcome this problem just do this

public void doGet(....)
{
doPost(request,response);
}

If you do this so you need not to worry about the method in HTML...I hope so..
 
Arjun Reddy
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the replies guys.
 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rajkumar balakrishnan:
Yes..by default doGet() method is taken by HTML



It is NOT by HTML but HTTP, the protocol which is the actual channel/mediator using which the client (browser) communicates with the server.


and if you want to overcome this problem just do this

public void doGet(....)
{
doPost(request,response);
}

If you do this so you need not to worry about the method in HTML...I hope so..



Here again, the HTML is just a tool which the client (browser) can understand (render) and display its contents. I guess Rajkumar was intended to say HTTP but he typed HTML .

What he has done here is he has called the doPost() method inside doGet(). So no matter which method is actually invoked from HTTP, the container(server) would delegate it to doPost() at the end ultimately -- just to explain the piece of code given by Rajkumar.

Hope this helps!
[ July 10, 2008: Message edited by: Raghavan Muthu ]
 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes of course i typed it wrongly and that even make others to understand the wrong concept. Thanks Raghavan... For your timely point out of human errors..
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's great and You are welcome
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic