Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doGet&session

 
deep nanda
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
i am often confusing with these two methods.could u please anybody help me out?
thanks
 
Neeraj Dheer
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
which two methods?

doGet() and doPost()? there is no method called session.
 
deep nanda
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
deep nanda
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks james.but how come i am getting 2 different outputs when i run on tomcat& weblogic servers!
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic