Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet question -standalone

 
H Singh
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having problems running this servlet as standalone, Can somebody please help ?


Servlet code :

package Headers;

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ShowHeadersServlet extends HttpServlet {
public void goGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException, IOException {

PrintWriter pw = res.getWriter();

pw.println("<html>");
pw.println("<head>");
pw.println("</head>");
pw.println("<body>");

Enumeration headers = req.getHeaderNames();
while(headers.hasMoreElements()){
String header = (String) headers.nextElement();
String value = req.getHeader(header);

pw.println(header+" = "+value);
}

pw.println("</body>");
pw.println("</html>");
}
}

I have put the class file (ShowHeadersServlet) under:
Tomcat5\webapps\ROOT\WEB-INF\classes\Headers

and modified web.xml (\Tomcat5\webapps\ROOT\WEB-INF\web.xml)

<servlet>
<servlet-name>ShowServlet</servlet-name>
<servlet-class>Headers.ShowHeadersServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>ShowServlet</servlet-name>
<url-pattern>/servlet/ShowHeadersServlet</url-pattern>
</servlet-mapping>


When i try to run servlet, i get(http://localhost:8080/servlet/ShowHeadersServlet)


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

Your help will be appreciated. Thanks
 
Wayan Suwastika
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think there is some thing wrong with your method signature.
in your servlet code you write

public class ShowHeadersServlet extends HttpServlet {

public void goGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException, IOException {
// ..........
}

to support GET or POST method you should override at least one service method :
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException, IOException {
// to handle http GET method
}
or
public void doPost(HttpServletRequest req,HttpServletResponse res)
throws ServletException, IOException {
// to handle http POST method
}

I think your method shoulbe doGet() not goGet()

regards,
WYasa
 
H Singh
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Wayan ...that worked
 
Ram Naresh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ha Ha!!! Abe Sardar Kya Huwa yaar, Apko.Book teekh se Pado...???
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic