aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HTTP POST-Method not supported by this URL. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HTTP POST-Method not supported by this URL." Watch "HTTP POST-Method not supported by this URL." New topic
Author

HTTP POST-Method not supported by this URL.

satheesh krishnaswamy
Ranch Hand

Joined: Mar 17, 2004
Posts: 137
Hi
I am using a simple html page whose contents will be submitted to a Servlet.
my html is

<FORM ACTION="/ServletLearning/servlet/a"
METHOD="POST">[ code]
I am only giving this part.
my servlet code is
[code] package j2src.test;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class a extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String title = "Reading All Request Parameters";
out.println(title +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1 ALIGN=CENTER>" + title + "</H1>\n" +
"<TABLE BORDER=1 ALIGN=CENTER>\n" +
"<TR BGCOLOR=\"#FFAD00\">\n" +
"<TH>Parameter Name<TH>Parameter Value(s)");
Enumeration paramNames = request.getParameterNames();
while(paramNames.hasMoreElements()) {
String paramName = (String)paramNames.nextElement();
out.print("<TR><TD>" + paramName + "\n<TD>");
String[] paramValues =
request.getParameterValues(paramName);
if (paramValues.length == 1)
{
String paramValue = paramValues[0];
if (paramValue.length() == 0)
out.println("<I>No Value</I>");
else
out.println(paramValue);
}
else
{
out.println("<UL>");
for(int i=0; i<paramValues.length; i++) {
out.println("><LI>" + paramValues[i]);
}
out.println("</UL>");
}
}
out.println("</TABLE>\n</BODY></HTML>");
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}



What could be the problem.In my web.xml I had configured like this
<servlet-mapping>
<servlet-name>a</servlet-name>
<url-pattern>/servlet/a</url-pattern>
</servlet-mapping>
<http-method>POST</http-method>

I am getting the error "HTTP POST-Method not supported by this URL.Can anyone help me in this?
Thanks and Regards
Satheesh.K


Regards,<br /> <br />Satheesh.K<br />-------------<br />SCJP 1.4<br />SCWCD 1.4
saravanan Paramasivan
Greenhorn

Joined: Sep 14, 2005
Posts: 3
hv u tried the servlet with full package name
j2se.test.a???
satheesh krishnaswamy
Ranch Hand

Joined: Mar 17, 2004
Posts: 137
Yes I did.
But Actually I need to submit the contents of the HTML form to the servlet.
I simply tried calling the servlet as <http://localhost:8080/ServletLearning/j2se.test.a> also.
Now it is saying that the file is not found.But I have that class in <webapps\ServletLearning\WEB-INF\classes\j2src\test>.
Dont know what is the problem.
Can you please explain?
Thanks a log
Priya Jothi
Ranch Hand

Joined: Jul 13, 2004
Posts: 168
Hi Satheesh,



<servlet-mapping>
<servlet-name>a</servlet-name>
<url-pattern>/servlet/a</url-pattern>
</servlet-mapping>

<http-method>POST</http-method>


Check whether there is a corresponding servlet definition present in web.xml.
for example:

<servlet>
<servlet-name>a</servlet-name>
<servlet-class>a</servlet-class>
</servlet>

I would suggest to change the servlet name to something else(except a .. coz it is the name of the servlet class..probably this shudn't be a pblm).
I tried the same code..it is working!!.

Ok now it is my turn..i have a small clarification in the above code itself..can any1 plz reply for this?.


<http-method>POST</http-method> <-- what is this?.


First of all, is this element valid if defined inside <webapp> element?.Should not it be enclosed inside <security-constraint> element?.Any comments?.

Regards,
Priya.
satheesh krishnaswamy
Ranch Hand

Joined: Mar 17, 2004
Posts: 137
Hi Priya,
Yes I did.I forget to include here.
My Web.xml looks like this:

I tried once more restarting the server.But of no use.Will IE 6.0 support this Post functionality?
The <http-method>POST</http-method> as you told,should be included under
<security-constraint> </security-constraint> only.I just tried it here.It did not work before and after this inclusion.

Can you please suggest me some ways to make it work.Did you tried calling submitting from the HTML form.The example I took from Core servlets and JSP Pages book only.So I am really surprised as what could be wrong in this?
Please Explain.

Thanks and regards
Satheesh.K
Priya Jothi
Ranch Hand

Joined: Jul 13, 2004
Posts: 168
Hey Satheesh,

Im also using IE6.0 only!!.No pblm in browser.If u r sure that ur web.xml looks like the one shown in ur above post..then where is the end tag for servlet element?!!


<servlet>
<servlet-name>a</servlet-name>
<servlet-class>j2src.test.a</servlet-class>
<servlet> <-- is this element missing in ur DD or u juz forgot to include here?.

<servlet-mapping>
<servlet-name>a</servlet-name>
<url-pattern>/servlet/a</url-pattern>
</servlet-mapping>



Try accessing the servlet itself directly.If this works obviously it should work when u submit ur HTML form also.I haven't tried using HTML.

Get back for further clarification if any!!

Regards,
Priya.
satheesh krishnaswamy
Ranch Hand

Joined: Mar 17, 2004
Posts: 137
Hey Priya,

Sorry for disturbing you.Yes it is just a typo error.I have </servlet> tag in my web.xml

When I try to call the servlet directly,I am getting it.(ofcourse without any datas,only the table is coming.It is expected).The HTML has to send the datas to servlet to get it displayed.Hence only the Post is creating problem.
I will give my HTML here.

Priya Jothi
Ranch Hand

Joined: Jul 13, 2004
Posts: 168
Now i got it whatz wrong with ur code..!!

Observe the following stmt in ur html

<FORM ACTION="/ServletLearning/servlet/a"METHOD="POST">

The above stmt should be changed to

<FORM ACTION="servlet/a" METHOD="POST">

Got it what i've done here?!."servlet/a" is ur actual url-mapping..then from where "ServletLearning" comes?!!

Make this small change & it'll work!!

Regards,
Priya.
Esam Ahmed
Ranch Hand

Joined: Aug 10, 2005
Posts: 101
<http-method></http-method> is declared within the

<web-resouce-collection></web-resource-collection> which in turn can be declared with <security-constraint></security-constraint> ....

The structure follows as:

<web-app ........>
<security-constraint>
<web-resouce-collection>
<web-resource-name>Resources</web-resource-name>
<url-pattern>/Beer/*</url-pattern>
<http-method>POST</http-method>
</web-resource-collection>
</security-constraint>
</web-app>

So, for simplicity, I would just recommend taking off the
<http-method>POST</http-method>
and see how it behaves...or just follow the standard .xml declarations....

Esam


Esam<br />SCJP 1.4, SCWCD 1.4
satheesh krishnaswamy
Ranch Hand

Joined: Mar 17, 2004
Posts: 137
Hi Priya,
Now I changed to
<FORM ACTION="/servlet/a" METHOD="POST">

Now I am getting HTTP 404 error.The requested resource is not available.

But when I try to invoke the servlet directly in IE

http://localhost:8080/ServletLearning/servlet/a

I am getting the HTML's(within the Servlet code) contents displayed.But not the datas which should come from HTML.

My War file name is ServletLearning.

As per ur suggestion when I click the button submit in the HTML,the URL formed is

http://localhost:8080/servlet/a

Hence I think some thing is wrong in this
Thanks and regards
Satheesh.K
Priya Jothi
Ranch Hand

Joined: Jul 13, 2004
Posts: 168
Hi Satheesh,


<FORM ACTION="/servlet/a" METHOD="POST">


In the above stmt remove the slash before "servlet" in the action attribute.
it should be simply "servlet/a".After this as u said access the below url.

http://localhost:8080/ServletLearning/servlet/a


Regards,
Priya.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HTTP POST-Method not supported by this URL.