[jboss-user] [Beginners Corner] - "HTTP Status 405: HTTP method GET is not supported by this U

michael.rollins do-not-reply at jboss.com
Tue Dec 2 16:04:11 EST 2008


I've been looking all over the web, and I keep coming up with the same solution, which is that you need to override doGet.  Seems simple, right?

However, I am overriding doGet, and I've even taken the simple servlet down to an even simpler level, and I'm still getting a 405 error.

Briefly, I have created a web service that will return a PNG image as a byte array to the client.  I created a simple client that receives the byte array.  That client is called by a servlet.  The servlet is supposed to write the byte array out to the browser.

Here's my servlet code:


  | package org.casm.gadget.chart.client;
  | 
  | import java.io.IOException;
  | 
  | import javax.servlet.ServletException;
  | import javax.servlet.ServletOutputStream;
  | import javax.servlet.http.HttpServlet;
  | import javax.servlet.http.HttpServletRequest;
  | import javax.servlet.http.HttpServletResponse;
  | 
  | /**
  |  * Servlet implementation class ChartClient
  |  */
  | public class ChartClientServlet extends HttpServlet {
  | 	private static final long serialVersionUID = 1L;
  | 	   
  |     /**
  |      * @see HttpServlet#HttpServlet()
  |      */
  |     public ChartClientServlet() {
  |         super();
  |         // TODO Auto-generated constructor stub
  |     }
  | 
  | 	/**
  | 	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  | 	 */
  | 	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  | 		
  | 		super.doGet(request, response);
  | 		
  | 		
  | 		try{
  | 		    ChartClient cc = new ChartClient();
  | 		    response.setContentType("image/png");
  | 		    ServletOutputStream out = response.getOutputStream();
  | 		    
  | 		    /*
  | 		    response.setContentType("text/html");
  | 		    PrintWriter out = response.getWriter();
  | 		    out.print("Hi");
  | 		    out.close();
  | 		    */
  | 		    
  | 		    out.write(cc.doTest());
  | 		    out.flush();
  | 		    out.close();
  | 		}catch(Exception e){
  | 		    e.printStackTrace();
  | 		}
  | 		
  | 	}
  | 
  | 	/**
  | 	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  | 	 */
  | 	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  | 		// TODO Auto-generated method stub
  | 		super.doPost(request, response);
  | 		doGet(request, response);
  | 	}
  | 
  | }
  | 
  | 

Everything up to writing the byte array out works.  The web service is returning, and the byte array is getting passed to the servlet, but alas, only 405.

If you look in the doGet method, you can see where I tried another, simpler version where the servlet only prints "Hi".  This also resulted in the 405 error.

I'm using JBoss 4.2.3.GA (the JDK6 version).

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4193874#4193874

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4193874



More information about the jboss-user mailing list