aspose file tools*
The moose likes Servlets and the fly likes Why does it die after init()? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Why does it die after init()?" Watch "Why does it die after init()?" New topic
Author

Why does it die after init()?

steve dowdall
Ranch Hand

Joined: May 23, 2001
Posts: 36
Hi, I have a servlet that goes into the init() method and then does not execute any other methods. Here is the init():
public void init(ServletConfig config) throws ServletException {
super.init(config);
System.out.println("inside init()!");
}

Am I missing something here? When I run it in Weblogic, I can see the invocation and it prints out the "inside init()" but then nothing else happens. My processRequest() does not execute.
Anyone know why?
Steve
ramkumar subbarao
Greenhorn

Joined: Aug 26, 2001
Posts: 5
Have you implemented doPost() and/or doGet() methods? You can call your processRequest() from these .
steve dowdall
Ranch Hand

Joined: May 23, 2001
Posts: 36
So if i use my processRequest method to do the lookup for my ejb, your saying I should call it from the doGet()? I thought I could do everything in the processRequest method. I'm confused about what these methods do. Are these methods both called automaticaly in the Servlet? Do they have to be? I dont think I can put ejb lookup code in the doGet method because it does not like the exceptions that I have to catch.
Steve
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
You need to call your processRequest method from doPost or doGet.
The service method dispatches to these methods.


------------------
Bosun
SCJP for the Java� 2 Platform


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Gerry Giese
Ranch Hand

Joined: Aug 02, 2001
Posts: 247
Steve,
First of all, call init() instead of init(ServletConfig). From J2EE API docs:
init() - A convenience method which can be overridden so that there's no need to call super.init(config).
Second, you *must* override either doGet()/doPost() or service() if you want your servlet to do anything. Kick off your processing from inside one of those methods.
If you don't care whether doGet() or doPost() is called, just override the HttpServlet.service(HttpServletRequest req, HttpServletResponse resp) method, since it's the one that by default reads the HTTP headers for GET or POST and forwards to doGet() or doPost(). If it matters, override the two methods separately instead of using service(). HTML forms always use POST, but users can also type http://myserver.com/myServlet?foo=bar, which results in a GET. Either way you use getParameter() to get your input values.
Good luck!


CJP (Certifiable Java Programmer), AMSE (Anti-Microsoft Software Engineer)
Author of Posts in the Saloon
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why does it die after init()?