File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes doGet&session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "doGet&session" Watch "doGet&session" New topic
Author

doGet&session

deep nanda
Greenhorn

Joined: May 05, 2005
Posts: 3
hi all,
i am often confusing with these two methods.could u please anybody help me out?
thanks
Neeraj Dheer
Ranch Hand

Joined: Mar 30, 2005
Posts: 225
which two methods?

doGet() and doPost()? there is no method called session.
deep nanda
Greenhorn

Joined: May 05, 2005
Posts: 3
I tried one small servlet program,that extends HttpServlet.i wrote one println stmt in doGet method,and one each in service(HttpServletRequest req....,.......) and in service(SrvletRequest req,......).I confused by seeing the output.here is the sample program.Is the output depends on webservers?

import java.io.*;

import javax.servlet.*;
import javax.servlet.http.*;

public class Serv extends HttpServlet
{
PrintWriter out;
public void doGet (HttpServletRequestrequest,HttpServletResponseresponse) throws ServletException, IOException
{
out.println(" This output is generated from a Servlet-doGet");
out.close();
}
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException{
out = res.getWriter();
super.service(req,res);

out.println("This output is generated from a Servlet-Normal service");
}
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
out.println("..... This output is generated from a Servlet-service");
out.println("..... Hi This is from Serv Servlet-Http service ");
}
}
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
Leave the service() methods alone. They are responsible for actually calling doGet() or doPost() or whatever HTTP "method" you're using. If you override it without calling the superclass' implementation, your doGet() method will never be called.


James Carman, President<br />Carman Consulting, Inc.
deep nanda
Greenhorn

Joined: May 05, 2005
Posts: 3
thanks james.but how come i am getting 2 different outputs when i run on tomcat& weblogic servers!
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
What output are you getting on WLS as opposed to Tomcat? Remember, Tomcat is supposed to be the "reference implementation" of the servlet spec. So, it's supposed to adhere to the spec pretty well. Let's take a look at what you get on WLS.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doGet&session