aspose file tools*
The moose likes Servlets and the fly likes The requested method POST is not allowed for the URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "The requested method POST is not allowed for the URL " Watch "The requested method POST is not allowed for the URL " New topic
Author

The requested method POST is not allowed for the URL

reddy palwai
Greenhorn

Joined: Nov 06, 2002
Posts: 11
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

Joined: Jul 18, 2002
Posts: 183
What value have you used in your response.setContentType("foo") method?
reddy palwai
Greenhorn

Joined: Nov 06, 2002
Posts: 11
Thanks Neil,
response.setContentType("text/html");
reddy palwai
Greenhorn

Joined: Nov 06, 2002
Posts: 11
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>");
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The requested method POST is not allowed for the URL
 
Similar Threads
method POST not allowed
Servlet Compilation
Resource not found
Help needed to 'Forward' Servlet to Servlet
regarding unsupported post method