Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in servlet

 
naresh govindaswmay
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class PostServlet extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>\n <body>\n");
out.println(" <h2>\n Hello World\n </h2>\n");
out.println(" </body>\n</html>\n");
out.flush();
out.close();
}
}
this is the program i tried. in run time it will saying some
"type Status report

message HTTP method GET is not supported by this URL

description The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).
Apache Tomcat/5.0.28"

this is the output i am getting . after i changed doPost() to doGet() i am getting the answer...can any one explain regarding this.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There isn't much to explain. If you execute a GET request (say, by typing the URL into the browser), then the servlet needs to override the doGet method in HttpServlet. The default method in HttpServlet produces this error message.
 
Chatura Dilan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, You are trying to get it, not post. You cannot doGet until you override the doGet Method

SCWCD Mock Exams
 
paritosh ranjan
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use doPost method by creating a html form like this
<form method=post action="servletname">
<input type="submit">
</form>

on pressing submit the servlet's doPost method will be called(you will also have to do the proper mapping in web.xml)

remember the default method is the GET method
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic