File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes goGet vs. doPost  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "goGet vs. doPost  " Watch "goGet vs. doPost  " New topic
Author

goGet vs. doPost

Scott Updike
Ranch Hand

Joined: Feb 16, 2006
Posts: 92
I have a simple problem that I hope someone can point me in the right direction:

I have a simple jsp page where I have a url that passes two parameters to a servlet that is different from the servlet specified in between the <form> tags. When I select the link, I get the following error:

The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).

Any idea why I'm getting this error?

Thanks,
Scott

Here's the cropped jsp file:

----------------
<p>
<form method="POST"
action="Update.do">
<center>
<input type="SUBMIT" name="mainbutton" value="Update Issue">
<input type="SUBMIT" name="mainbutton" value="Back to Main">
</center>


...lots of code....

<a href="<c:url value='/DeleteComm.do'><c aram name='issuename' value='${results.name}' /><c aram name='commentid' value='${el.commid}' /></c:url>">Delete</a>

------------
When I move my mouse over the link, the correct parameters show up so the link is correct.

Here's the servlet code for DeleteComm.java

-----------------

import javax.servlet.http.*;
import javax.servlet.jsp.jstl.sql.*;
import javax.servlet.*;
import java.io.*;
import java.sql.*;
import java.util.*;

public class deleteComment extends HttpServlet {

public void doGet (HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {

sqlDAOMySQL sqlConn = (sqlDAOMySQL) getServletContext().getAttribute("dbase");
String deleteName = request.getParameter("issuename");
String Id = request.getParameter("commentid");
Integer deleteId = java.lang.Integer.valueOf(Id);
IssueTO updatedIssue = new IssueTO();

try {


sqlConn.deleteComment(deleteName, deleteId);
updatedIssue = sqlConn.getIssue(deleteName);

request.setAttribute("results",updatedIssue);
RequestDispatcher view = request.getRequestDispatcher("editIssue.jsp");
view.forward(request, response);

} catch (Exception ex) {

r...code

}
} //do post

} //end class
---------------------

Here's the DD snippet...

<servlet>
<servlet-name>DeleteComm</servlet-name>
<servlet-class>com.baissue.deleteComment</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DeleteComm</servlet-name>
<url-pattern>/DeleteComm.do</url-pattern>
</servlet-mapping>
ak pillai
author
Ranch Hand

Joined: Feb 11, 2006
Posts: 288
Your JSP is doing an HTTP POST and your Servlet only has a doGet() method.

What you need to do is add a doPost() method, which just calls your doGet() method. Add the following method in your servlet and you should be fine.


[ July 12, 2006: Message edited by: ak pillai ]

java j2ee job interview questions with answers | Learn the core concepts and the key areas
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Originally posted by ak pillai:
Your JSP is doing an HTTP POST and your Servlet only has a doGet() method.


No, he said that this is a result of clicking the link, not submitting the form.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
abhijit Ohal
Ranch Hand

Joined: Mar 10, 2006
Posts: 64
i think you missout '?' after DeleteComm.do also in your link querry string missout '&' between to request parametrs
see the correct format bellow

eg.
http://www.coderanch.com/t/362968/Servlets/java/goGet-vs-doPost
 
Don't get me started about those stupid light bulbs.
 
subject: goGet vs. doPost
 
Similar Threads
http 404 error
Starting out on Servlets - from Head First Servlets and JSP
HFSJ book: Cookie example chapter 6 plz Help :(
Question on BUTTON name/value pairs sent from JSP
i get ' null ' for jsp init params