• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The requested method POST is not allowed for the URL

 
reddy palwai
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to post information from an html file to a servlet.
I have
<FORM ACTION="test" METHOD="POST" name=sample>
in my html file
and
I have
public void doPost(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
in my java servlet file.
My Java is compiling fine, but when I post information from my html file, I am getting the following error
/////////////////
Method Not Allowed
The requested method POST is not allowed for the URL.
//////////////////
I tried changing POST to GET...then it is downloading the file instead of opening it.
May be something is wrong with configuration.
Please help.
thanks in advance,
reddy
 
Neil Laurance
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What value have you used in your response.setContentType("foo") method?
 
reddy palwai
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Neil,
response.setContentType("text/html");
 
reddy palwai
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my simple code
Html file
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>A Sample FORM using POST</TITLE>
</HEAD>
<BODY BGCOLOR="#FDF5E6">
<H1 ALIGN="CENTER">A Sample FORM using POST</H1>
<FORM ACTION="test" METHOD="POST" name=samp>
Name:
<INPUT TYPE="TEXT" NAME="name"><BR>
<INPUT TYPE="SUBMIT" VALUE="Submit Order">
</FORM>
</BODY>
</HTML>

SERVLET

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

public class test extends HttpServlet
{
public void doPost(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
String para = req.getParameter("name");
ServletOutputStream out = res.getOutputStream();
// set content type and other response header fields first
res.setContentType("text/html");
// then write the data of the response
out.println("<HEAD><TITLE> Testing </TITLE></HEAD><BODY>");
out.println("<h1> "+para+"</h1><br>");
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic