Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

need an explanation..  RSS feed

 
trupti nigam
Ranch Hand
Posts: 640
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Below is the code for the PostServlet.java
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();
}
}

If I try to access the servlet I get an error saying
message HTTP method GET is not supported by this URL
I need an explaination for this?
thanks in advance..
trupti
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have you checked this post?
 
Nikki Aniban
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Trupti!
When you access a Servlet through a URL, the default HTTP method that will be called is GET, which will consequently look for the doGet() method. Since your PostServlet only defines the doPost(), an error will occur.
Like Andres, I usually define a doGet() method that calls the doPost() method (or the other way around).
Hope this answers your question. Goodluck!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!