aspose file tools*
The moose likes Servlets and the fly likes How to call a doHead method inside a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to call a doHead method inside a servlet" Watch "How to call a doHead method inside a servlet" New topic
Author

How to call a doHead method inside a servlet

Malli Raman
Ranch Hand

Joined: Nov 07, 2001
Posts: 312
Hi,
I am just trying to call a doHead() method inside the servlet. But in
the servlet it is calling only doGet method and it is not calling
doHead method. But in the Orielly book it has mentioned the service
method will call doHead method and followed by the doGet method and
returns only the header details and suppress all the body output. But it
is not happening. Whether I have missed something.
<------------------------DoHead.jsp-------------------------------------->
<HTML>
<HEAD>
<TITLE> Testing the doHead method </TITLE>
</HEAD>
<BODY>
<FORM METHOD = "HEAD" ACTION ="SimpleHeadServlet">
<INPUT TYPE = "SUBMIT" NAME= "SUBMIT" VALUE= "Click to call Head
method">
</FORM>
</BODY>
</HTML>
<------------------------- SimpleHeadServlet ----------------------------->
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SimpleHeadServlet extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse
response)
throws ServletException,IOException
{
response.setContentType("Text/html");
PrintWriter out = response.getWriter();
out.println("Method Name: " + request.getMethod());
if (request.getMethod().equals("HEAD"))
{
out.println("Method Name is doHead");
return;
}
out.println("Inside the doGet method");
}
public void doHead()
{
System.out.println("Inside the doHead method");
}
}

Thanks & Regards,
M.S.Raman
Gayan Balasooriya
Ranch Hand

Joined: Jul 31, 2002
Posts: 51
There is no doHead() method defined in HttpServlet class in 2.2 API.
But it is there in 2.3 API.
And the correct method is
doHead(HttpServletRequest req, HttpServletResponse resp)
throws ServletException,java.io.IOException
not doHead().
Gayan Balasooriya
SCJP,SCWCD
http://www.gayanb.com - Free Java/J2EE/J2ME books and mock exams


SCJP, SCWCD
Malli Raman
Ranch Hand

Joined: Nov 07, 2001
Posts: 312
Originally posted by Gayan Balasooriya:
There is no doHead() method defined in HttpServlet class in 2.2 API.
But it is there in 2.3 API.
And the correct method is
doHead(HttpServletRequest req, HttpServletResponse resp)
throws ServletException,java.io.IOException
not doHead().
Gayan Balasooriya
SCJP,SCWCD
http://www.gayanb.com - Free Java/J2EE/J2ME books and mock exams

Hi Gayan Balasooriya,
Thanks for replying me. I have changed the doHead() method to
public void doHead(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException
{
System.out.println("Inside the doHead method");
}
But still i am getting this resposne only "Method Name: GET Inside the doGet method ". I am using weblogic 7.1 application server which supports Servlet 2.3.
Regards,
M.S.Raman
Adnan Ahmed
Greenhorn

Joined: Aug 18, 2003
Posts: 17
Hi Jojit
I think this is not right way to invoke doHead method of servlet. Because to invoke doGet u r using form tag of html and the attribute "method" of form just support two HTTP method either get or post.
And the reason the page invoking doget is that the form using invalid method thats why form default method will be called which is Get.
If i m right then tell me
okie


SCJP1.2 <br />SCWCD1.4
Adnan Ahmed
Greenhorn

Joined: Aug 18, 2003
Posts: 17
Hi Jojit
I think this is not right way to invoke doHead method of servlet. Because to invoke doGet u r using form tag of html and the attribute "method" of form just support two HTTP method either get or post.
And the reason the page invoking doget is that the form using invalid method thats why form default method will be called which is Get.
If i m right then tell me
okie
Adnan Ahmed
Greenhorn

Joined: Aug 18, 2003
Posts: 17
Hi Jojit
I think this is not right way to invoke doHead method of servlet. Because to invoke doGet u r using form tag of html and the attribute "method" of form just support two HTTP method either get or post.
And the reason the page invoking doget is that the form using invalid method thats why form default method will be called which is Get.
If i m right then tell me
okie
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
sounds like telnet might be your friend here:
>telnet myserver.com myport
HEAD /SimpleHeadServlet HTTP/1.0
Gayan Balasooriya
Ranch Hand

Joined: Jul 31, 2002
Posts: 51
Originally posted by Adnan Ahmed:
Hi Jojit
I think this is not right way to invoke doHead method of servlet. Because to invoke doGet u r using form tag of html and the attribute "method" of form just support two HTTP method either get or post.
And the reason the page invoking doget is that the form using invalid method thats why form default method will be called which is Get.
If i m right then tell me
okie

I think you are correct.According to HTML specification METHOD attribute of
FORM tag can be only GET or POST.
Read this

Gayan Balasooriya
SCJP,SCWCD
http://www.gayanb.com - Free Java/J2EE/J2ME books and mock exams
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to call a doHead method inside a servlet