• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

goGet vs. doPost

 
Scott Updike
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
abhijit Ohal
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic