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{
		....		
	}		

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
15 Comment threads
5 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
20 Comment authors
Twinkle KaurnareshAbcd PoptaniAnanthaJasneet Recent comment authors
newest oldest most voted
Valera
Guest
Valera

I had same problem. The decision was to remove auto generated
super.doGet(req, resp); in my doGet method

Nhan Nguyen
Guest
Nhan Nguyen

Thanks! Your comment solved my problem.

Jasneet
Guest
Jasneet

It solved my issue as well. Thanks a lot Valera!

Anantha
Guest
Anantha

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);

}
}

Twinkle Kaur
Guest
Twinkle Kaur

service method is used in GenricServlet, try using doGet or doPost method

Kamidi Harish
Guest
Kamidi Harish

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… Read more »

naresh
Guest
naresh

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

Abcd Poptani
Guest
Abcd Poptani

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.

Simon
Guest
Simon

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.

Stanislav
Guest
Stanislav

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”)… Read more »

David Carlin
Guest
David Carlin

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

Antonio
Guest
Antonio

Very good. Problem resolved…

Best regards.

sites
Guest
sites

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… Read more »

pam
Guest
pam

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. @Controller @RequestMapping("/moving-cable-tv/confirm_address") public class MoversConfirmAddressController { @RequestMapping(value="/confirm_address", method = RequestMethod.GET) public View get(@ModelAttribute("moversCommand") MoversCommand moversCommand) { return new InternalResourceView("/WEB-INF/jsp/confirm_address.jsp"); } @RequestMapping(method = RequestMethod.POST) public View post(@ModelAttribute("moversCommand") @Valid MoversCommand moversCommand, BindingResult result, RedirectAttributes attr) { if (result.hasErrors()) { logger.info("Validation Error(s) : {}", result.getAllErrors().size()); attr.addFlashAttribute("org.springframework.validation.BindingResult.moversCommand", result); attr.addFlashAttribute("MoversCommand", moversCommand); return new RedirectView("/moving-cable-tv/moving_form"); } else { if (moversCommand.getServiceAddr1().equalsIgnoreCase("noAddrAvailable")) { logger.debug("Confirmed Address Error - NoMatch"); moversCommand.setStatus("NoMatch"); return new RedirectView("/moving-cable-tv/moving_form"); } if (moversCommand.getCustomerIntent().equalsIgnoreCase("new")||moversCommand.getCustomerIntent().equalsIgnoreCase("current")) {… Read more »

suresh
Guest
suresh

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?

tushar
Guest
tushar

Suresh please paste your code here

Zing
Guest
Zing

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. :)

RuchiBohra
Guest
RuchiBohra

For Java public class Secure extends HttpServlet { /** * Processes requests for both HTTP GET and POST methods. * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { String username,secq; username=request.getParameter("un"); secq=new model.Sec1().sec(username); HttpSession session=request.getSession(); session.setAttribute("un", username); if(secq!=null) { session.setAttribute("sq",secq); response.sendRedirect("security.jsp"); } } finally { out.close(); } } // /** * Handles the HTTP GET method. * @param request servlet request * @param response servlet… Read more »

Larry Trussell
Guest
Larry Trussell

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?