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
posted
0
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
posted
0
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: 1506
posted
0
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
posted
0
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)<br />Author of <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi" target="_blank" rel="nofollow">Posts in the Saloon</a>
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.