• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

The requested method POST is not allowed for the URL

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Neil,
response.setContentType("text/html");
 
reddy palwai
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>");
}
}
 
I think she's lovely. It's this tiny ad that called her crazy:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic