Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HTTP Status 405 - HTTP method GET is not supported by this URL

 
Abhilash Ravishankar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Index</title>
</head>
<body>
<form action="/loggin" method="post">
<h3>Enter the Vehicle ID</h3> <input type="text" name="vehicleID" />
<br>
<br>
<input type="submit" value="Submit"/>

</form>
</body>
</html>
LogginServlet.java(doPost method file—Servlet)
package org.nissan.abhi;

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;

import org.nissan.service.logginservice;



public class logginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;


protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String vehicleID;
vehicleID= request.getParameter("vehicleID");
logginservice lgnsrv = new logginservice();

boolean result = lgnsrv.authenticate(vehicleID);

System.out.println("Hai");

if(result)
{
response.sendRedirect("success.jsp");
return;
}
else
{
response.sendRedirect("index.jsp");
return;
}


}

}

Logginservice.java
package org.nissan.service;

public class logginservice {

public boolean authenticate(String VehicleID){
if(VehicleID == null || VehicleID.trim()== " ")
{
return false;
}
return true;
}

}

Success.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Success</title>
</head>
<body>
<h5>Loggin Successful</h5>
</body>
</html>
Web.XML
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Nissan1</display-name>
<servlet>
<servlet-name>logginServlet</servlet-name>
<servlet-class> org.nissan.abhi.logginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>logginServlet</servlet-name>
<url-pattern>/loggin</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>



 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64606
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no doGet() in your servlet, so of course it's not supported.
 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear is right. Most of the doXXX methods do nothing but cause an error 405 unless you override them. This definitely is the case for doGet and doPost.
 
Abhilash Ravishankar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
package org.nissan.abhi;

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;

import org.nissan.service.logginservice;



public class logginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException
{

try{
doPost(req,res);
}
catch(IOException e)
{

}

}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


String vehicleID;

response.setContentType("text/html");

vehicleID= request.getParameter("vehicleID");
logginservice lgnsrv = new logginservice();

boolean result = lgnsrv.authenticate(vehicleID);



if(result)
{
response.sendRedirect("success.jsp");
return;
}
else
{
response.sendRedirect("index.jsp");
return;
}


}

}

I tried this way...Its working fine from the servlet to another JSP(success.jsp) but its not transferring control from index.jsp to logginServlet.java...Please help me
 
Abhilash Ravishankar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help. Now its working fine...When I wrote the dummy method of doGet and called doPost from it, it started working.But One more thing I didn't understood is, until I closed the eclipse and opened it, it was not working.Is there any way I can fix this ?
 
Tim Moores
Bartender
Posts: 2674
33
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even though the servlet may now react in the same way to a GET and a POST, other specification-conforming HTTP implementations along the way (like proxies, caches etc) may not; in fact, it is likely that they won't. So any code that treats GET and POST as if they were interchangeable is a bug waiting to happen. The HTTP specification (which you should read if you're serious about web development) is actually very clear about this.


catch(IOException e)
{
}

You should never do this - you really need to handle exceptions properly. At the least, print the error message to a log where you will see it.
 
Abhilash Ravishankar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim, I will follow what you have told. I will handle the exception.Thanks for your reply.It helped me a lot...
 
Cole Terry
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhilash Ravishankar wrote:But One more thing I didn't understood is, until I closed the eclipse and opened it, it was not working.Is there any way I can fix this ?


Are you running Tomcat inside Eclipse? If so, that is the reason. When you close Eclipse, Tomcat is stopped as well.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic