This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
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()); }
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?
Jeroen Wenting
Ranch Hand
Joined: Oct 12, 2000
Posts: 5093
posted
0
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.
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?
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...
Adeel Ansari
Ranch Hand
Joined: Aug 15, 2004
Posts: 2874
posted
0
Jeroen, I understand. I am with you. [ December 23, 2004: Message edited by: Adeel Ansari ]
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 ]
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12271
1
posted
0
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
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
Joined: Aug 15, 2004
Posts: 2874
posted
0
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.
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12271
1
posted
0
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
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
Joined: Aug 15, 2004
Posts: 2874
posted
0
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
Rancher
Joined: Mar 22, 2000
Posts: 12271
1
posted
0
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
Joined: Aug 15, 2004
Posts: 2874
posted
0
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. .
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
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
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
Joined: Aug 15, 2004
Posts: 2874
posted
0
Arun, sometimes we need to delete the work directory of tomcat after making some changes in our code.