• Post Reply Bookmark Topic Watch Topic
  • New Topic

Newbie here tyrint o understand Servlets

 
Arjun Reddy
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
  • 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.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Welcome
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
  • 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: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's great and You are welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!