aspose file tools*
The moose likes Servlets and the fly likes HTTP Status 405 - HTTP method GET is not supported by this URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "HTTP Status 405 - HTTP method GET is not supported by this URL" Watch "HTTP Status 405 - HTTP method GET is not supported by this URL" New topic
Author

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

Abhilash Ravishankar
Greenhorn

Joined: Nov 16, 2011
Posts: 9
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

Joined: Jan 10, 2002
Posts: 61010
    
  65

There is no doGet() in your servlet, so of course it's not supported.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Abhilash Ravishankar
Greenhorn

Joined: Nov 16, 2011
Posts: 9
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

Joined: Nov 16, 2011
Posts: 9
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
Rancher

Joined: Sep 21, 2011
Posts: 2408
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

Joined: Nov 16, 2011
Posts: 9
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

Joined: Nov 23, 2011
Posts: 45
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HTTP Status 405 - HTTP method GET is not supported by this URL