HTTP Status 405 – HTTP method GET is not supported by this URL
The HTTP status 405 is a very common error message in Java Servlet.
HTTP Status 405 - HTTP method GET is not supported by this URL
type Status report
message HTTP method GET is not supported by this URL
description The specified HTTP method is not allowed for the requested resource
(HTTP method GET is not supported by this URL).
Apache Tomcat/6.0.20
Solution
This is always caused by following two reasons
1) You do not have a valid doGet() method, when you type the servlet’s path in address bar directly, the web container like Tomcat will try to invoke the doGet() method.
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException{
....
}
2) You made a HTTP post request from a HTML form, but you do not have a doPost() method to handle it. The doGet() can not handle the “Post” request.
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException{
....
}
I had same problem. The decision was to remove auto generated
super.doGet(req, resp); in my doGet method
Your comment solved my problem… Thanks a ton!
Thank you …. ur comment solved my problem
It solved my issue as well. Thanks a lot Valera!
Thanks! Your comment solved my problem.
Reason #2 sounds like a bug in the web container. If it can’t handle POST, it should say that it can’t handle POST, rather than saying it can’t handle GET. 🙂
i m getting this type of problem
HTTP Status 405 – Method Not Allowed
Type Status Report
Message HTTP method GET is not supported by this URL
Description The method received in the request-line is known by the origin server but not supported by the target resource.
Apache Tomcat/9.0.21
use doPost method
package com.user;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.UUID;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.connection.DatabaseConnection;
/**
* Servlet implementation class UserLogin
*/
@WebServlet(“/UserLogin”)
public class UserLogin extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String uname = request.getParameter(“username”);
String pass = request.getParameter(“password”);
try {
HttpSession hs = request.getSession();
String tokens = UUID.randomUUID().toString();
Connection con = DatabaseConnection.getConnection();
Statement st = con.createStatement();
ResultSet resultset = st.executeQuery(“select * from tbluser where uname='” + uname + “‘ AND password='” + pass + “‘”);
if (resultset.next()) {
String fullName=resultset.getString(2);
hs.setAttribute(“uname”, uname);
hs.setAttribute(“fullName”, fullName);
hs.setAttribute(“mobileNo”, resultset.getString(3));
response.sendRedirect(“user-dashboard.jsp?_tokens='” + tokens + “‘”);
} else {
String message = “Invalid credential”;
hs.setAttribute(“message”, message);
response.sendRedirect(“user-login.jsp”);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
getting 405 error, Status Report Message HTTP method GET is not supported by this URL. Description The method received in the request-line is known by the origin server but not supported by the target resource.
Hi…
Sir I am getting some problem with below code please tell the solution for the same
“web.xml”
LoginServlet
practice.harish.LoginServlet
LoginServlet
/login
LoginServlet.java
package practice.harish;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType(“text/html”);
PrintWriter out=response.getWriter();
String uname=request.getParameter(“uname”);
String upwd=request.getParameter(“upwd”);
out.println(“”);
out.println(“”);
out.println(“”);
out.println(“”);
if (uname.equals(“harish”)&&upwd.equals(“java007”))
{
out.println(“Login Success”);
}else
{
out.println(“Login Failure”);
}
out.println(“”);
out.println(“Login Page“);
out.println(“”);
}
}
Loginform.html
Durga SoftWare Solutions
User Login Page
User name
Password
This is my first Servlet, after i Run the project i am getting the login page but it is not giving any success message when i click on login button.. as per my project..
please help me in this..
i am trying to build a login logout session using cookies, but when clicking on logout link it generates a error 405 in glassfish server and states http method GET not supported by this url . And i have used doPost() method.
Message HTTP method GET is not supported by this URL
HTTP method GET is not supported by this URL
When I run on Server a java servlet with apache tomcat 9 in eclipse, I don’t see console message Reloading context name with name [context name] showing up. Maybe that is why my project not working.and giving http status 405 – http method not allowed !!
I am attaching doPost(), index.html and web.xml files
HTTP Status 405 – Method Not Allowed
Type Status Report
Message HTTP method GET is not supported by this URL
Description The method received in the request-line is known by the origin server but not supported by the target resource.
———
package com.telusko;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class AddServlet extends HttpServlet
{
public void Service(HttpServletRequest req,HttpServletResponse res) throws IOException
{
int i=Integer.parseInt(req.getParameter(“num1”));
int j=Integer.parseInt(req.getParameter(“num2”));
int k=i+j;
PrintWriter out=res.getWriter() ;
out.println(k);
//System.out.println(“result is “+k);
}
}
service method is used in GenricServlet, try using doGet or doPost method
thanks a lot!! i spent hours on this..using doGet solved my problem
Thanks. I had by mistake used a doGet method instead of a doPost method on the SERVER side and my CLIENT was using a HttpPost method. The mismatch caused the server to issue a 405 status.
I’v got the similar error HTTP Status 405 – Request method ‘POST’ not supported
Here is the code of my update controller
@Controller
@RequestMapping(“/updateCd”)
public class UpdateCdController {
@Autowired
private CdService cdService;
@RequestMapping(value = “/{id}”, method = RequestMethod.GET)
public String showUpdateForm(@PathVariable int id, ModelMap model) {
Cd cd = cdService.getCd(id);
model.addAttribute(“updateCD”, cd);
return “updateCd”;
}
@RequestMapping(method = RequestMethod.POST)
public String updateForm(@ModelAttribute(value = “updateCD”) Cd cd, BindingResult result) {
if (result.hasErrors()) {
return “updateCd”;
} else {
cdService.updateCd(cd);
return “redirect:content”;
// }
}
}
}
But the similar controller works absolutely normally
Here is the code of add controller
@Controller
@RequestMapping(“/addCd”)
public class AddCdController {
@Autowired
private CdService cdService;
@RequestMapping(method = RequestMethod.GET)
public String showAddForm(ModelMap model) {
Cd cd = new Cd();
model.addAttribute(“addCD”, cd);
return “addCd”;
}
@RequestMapping(method = RequestMethod.POST)
public String addForm(@ModelAttribute(value = “addCD”) Cd cd, BindingResult result) {
if (result.hasErrors()) {
return “addCd”;
} else {
cdService.addCd(cd);
return “redirect:content”;
}
}
}
Mr Mkyong –
Your “HTTP Status 405 – HTTP Method GET Is Not Supported By This URL” answer saved me much time and frustration in troubleshooting my project. I have come to your posts often as I deploy my first Google AppEngine project and the information you provide with such care is accurate and helpful. Thank you for the contribution to learning and success you are making.
Regards,
David Carlin
Very good. Problem resolved…
Best regards.
Needed to post you the little bit of note in order to give thanks as before for the superb things you’ve contributed here. It has been so surprisingly open-handed with you to give openly precisely what a number of us would have offered as an e-book to help with making some cash on their own, and in particular given that you might have done it if you considered necessary. The thoughts likewise acted like the fantastic way to be certain that other people have the identical dreams just like my own to know many more on the subject of this condition. I know there are lots of more enjoyable opportunities up front for folks who read through your site.
Hi,
I am getting The same Error “Request method ‘GET’ not supported”.
When i hit localhost:…./moving-cable-tv/confirm_address
this error comes.
This is how my controller class looks like. Can some one help me.
hi,
i had a same issue when try to post server return 405 method not allowed.
i handle servlet dopost and doget
in form if i use method get its working when use post i got 405 error
how to solve this issue?
Suresh please paste your code here
In the past couple of weeks I have started getting the “HTTP Status 405 – HTTP method GET is not supported by this URL” message when I try to use some links from the MY MSN homepage. I’m not doing any programing just trying to go to a link on the page. I’m using Internet Explorer 8. Is there anything I should be changing to try and fix this?
This error is caused by the server site, nothing to do with the client. Please contact the link owner / website owner about this issue.
For Java
i am having a problem as i am clicking on submit button..It says method POST is not supported by url..i have checked the mapping.m not able to find the solution..