• 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

HTTP method POST is not supported by this URL

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ,
i wrote an html file
....
<form name="Post your reminders here"
method="POST"
action="http://localhost:8080/examples/servlet/request">
....
and the request.java is
import java.io.*;
import javax.servlet.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import javax.servlet.http.*;

public class request extends HttpServlet
{
public String getServletInfo()
{
return " Servlet connect to database and show the result of a SELECT";
}
private Connection dbcon;
public void init(ServletConfig config) throws ServletException
{
String loginUser="postgres";
String loginPasswd="postgres";
String loginUrl="jdbc ostgresql://localhost/remind";
try
{
Class.forName("org.postgresql.Driver");
dbcon=DriverManager.getConnection(loginUrl,loginUser,loginPasswd);
}
catch (ClassNotFoundException ex)
{
System.err.println("ClassNotFoundException:"+ex.getMessage());
throw new ServletException("Class not found Error");
}
catch(SQLException ex)
{
System.err.println("SQLException:"+ex.getMessage());
}

}
public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("<HTML><Head><Title>REQUEST</Title></Head>");
out.println("<Body><H1>REQUEST</H1>");
try
{
Statement statement=dbcon.createStatement();

String query="SELECT * FROM remind";
ResultSet rs=statement.executeQuery(query);
out.println("<TABLE border>");
while(rs.next())
{
String m_name=rs.getString("name");
String m_time=rs.getString("time");
String m_subject=rs.getString("subject");
out.println("<tr>"+
"<td>"+m_name+"</td>"+
"<td>"+m_time+"</td>"+
"<td>"+m_subject+"</td>"+
"</tr>");
}
out.println("</TABLE></Body><HTML>");
statement.close();
}
catch(Exception ex)
{
out.println("<HTML>" +
"<Head><Title>" +
"remind:Error" +
"</Title></Head>\n<Body>"+
"<P>SQL error in doGet:" +
ex.getMessage() +"</P></Body></HTML>");
return;
}
out.close();
}
}
the database is in postgresql
now when i access the html file i get the error

HTTP method POST is not supported by this URL
could somebody help me?
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first change the classname of your servlet.
1) naming it "request" is highly confusing and may well be causing your error.
2) starting classnames with a lowercase letter is against all Java naming conventions.
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeroen,
How incredibly helpful you are. Yes, if Arun only changes his class name, it will begin to work, right?

Arun,
The error you are getting is probably related to how you have configured your servlet engine and/or your Web server. However, since I could find no details (in your post) about what servlet engine and Web server you are using, there isn't much more I can offer you. Perhaps try reading the documentation for your servlet engine and Web server?

Good Luck,
Avi.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Be nice, please.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's possible indeed that it will make things work.
After all, a class named simply "request" may cause an application server to do things it should not...
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeroen,
I understand. I am with you.
[ December 23, 2004: Message edited by: Adeel Ansari ]
 
Avi Abrami
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following works fine for me using Apache 1.3.12 Web server on SUN [sparc] Solaris 7 and JDK 1.4.2

My servlet:

My HTML page that calls the servlet:

I did notice some errors in the HTML you posted, Arun. That may be the cause of your problem.

Nevertheless, I still think it has something to do with your environment.

In my environment, I have configured Apache Web Server so that it automatically loads servlet classes. All I have to do is compile the class, and put the compiled class in a certain directory, and Apache will pick it up (provided I supply the correct URL).

Unfortunately, since you haven't given any details of your environment, I can't help you further.

Good Luck,
Avi.
[ December 26, 2004: Message edited by: Avi Abrami ]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The use of "/servlet/"

indicates you are using the "Invoker" servlet to locate simple servlet classes. Read more about Invoker in this ranch FAQ.
Use of the invoker for any but the most trivial servlet projects is going to lead to nothing but trouble.
Bill
 
Avi Abrami
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
William,

Read more about Invoker in this ranch FAQ


But I'm not using "Tomcat" (I'm using "JServ"), and this isn't a Web application, it's just a servlet, so there isn't a "web.xml" file.

So how is that FAQ entry relevant?

Good Luck,
Avi.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Avi,
As you said that its quite OK in your case. But we and the link given by William are just talking about the best practices, future changes and enhancements, drawbacks.

And about the name of the servlet as 'request' might work fine. But we were just saying that it may not work because different containers has different implementations. Servlet spec. doesn't say, "you can not name your servlet as request". If it is working with you then its cooool. Actually me haven't tried it, and still dont want to, it doesn't make any sense to me though.

thanks.
[ December 26, 2004: Message edited by: Adeel Ansari ]
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But I'm not using "Tomcat" (I'm using "JServ"), and this isn't a Web application, it's just a servlet, so there isn't a "web.xml" file.


The servlet specification (download it from here) says that all servlets are part of web applications and that web applications MUST be configured with the web.xml deployment descriptor.
SO - unless your version of JServe is more than about 3 years old, your servlet must follow that API.
Bill
 
Avi Abrami
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
William,


unless your version of JServe is more than about 3 years old


I believe it is, actually.

In any case, no-one still has provided an answer for poor, old Arun.
And I think I've shown that Jeroen's suggestion (of changing the class
name) is not the solution.

Perhaps you'd care to try and address the original question?

Good Luck,
Avi.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Avi,
Jeroen was not definite about his answer. He just said it may be the cause of error. anyways, now its proved that you can name your servlet as 'request'.
cheers.

Sometimes we can not provide the actual answer. So, what we usually do is to suggest something, or apply some guesses.

And Arun where are you. :roll:
I think he got it fixed.
[ December 28, 2004: Message edited by: Adeel Ansari ]
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I recall, you get "HTTP method POST is not supported by this URL" when the URL actually finds a servlet but that servlet does not override the doPost method. That message comes from the base class such as HttpServlet.
Causes could include -
method signature does not match doPost so the method is not really overridden,
the server has the URL mapped to another servlet
Question for "Avi Abrami"

You said

I believe it is, actually.


- are you getting some communication from the original poster "arun andrew" that we are not seeing? It looks rather odd that the first post does not appear to say anything about JServ being the servlet container but your 12/26/04 message says:

But I'm not using "Tomcat" (I'm using "JServ"), and this isn't a Web application, it's just a servlet, so there isn't a "web.xml" file.

So how is that FAQ entry relevant?


Bill
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bill,
I think in the Avi's post you mentioned, she was talking about her try. She tried to make a servlet with the name "request". So, I think she used Jserv. she was not talking about the Arun Andrew, but not sure though.

And I am not getting any communication from Avi that can not be seen. .

cheers.
[ December 28, 2004: Message edited by: Adeel Ansari ]
 
arun andrew
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
thank you for the suggestions.i didn't change the name request but when i restarted the TOMCAT server the error is gone.i don't know how it happened but nonetheless am happy.guess whenever you make changes in the servlet code its better to restart the server otherwise the old values will be repeated or something.hope someone can give a better answer.
regards
Andrew
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

hope someone can give a better answer.




Read up on the "reloadable" attribute of your context configuration.
http://jakarta.apache.org/tomcat/tomcat-5.5-doc/config/context.html


And..
When you get a chance, rename that "request" object of yours.
[ December 29, 2004: Message edited by: Ben Souther ]
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Arun:

Congrats..Ur question(which probably never got the right answer) has triggered a series of discussions which were worthy to read.

Avi

Its never a good practice to name the files with the names which are keywords in that language..unless u r the one who developed that language...this is a common rule..hope u know that

Cheers
Rakesh
 
Avi Abrami
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rakesh,
For your information, the impression I got from Jeroen's reply was that he was implying that Arun's servlet was not working because Arun had written non-standard code. I felt that was misleading, and since it looks to me that Arun is a newbie, giving misleading information can be very harmful (for newbies).

It would appear that I have (still) failed to make that clear.

I am not advocating writing non-standard code, I'm just saying that it does not help the person seeking an answer, when they are given misleading information. And, in my opinion, Jeroen's answer was misleading.

Now if you feel (as you implied in your post) that Arun has still not received "the right answer" to his question, perhaps you can offer it -- rather than espousing the benefits of writing standard code?

Good Luck,
Avi.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arun,
sometimes we need to delete the work directory of tomcat after making some changes in our code.

Avi,
We understood.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic