Hi all! I have built a class that extends HttpServlet. I have implemented getBrowser() and setBrowser and so on. In this methods I try to locate the browser using, Os and versions. It's just that when I try to use it in my JSP it returns null. The init() method isn't called? How is that?
I have set a string In init and tries to return this string in getBrowser()
I'm pussled, tied and a bad javaprogrammer [ November 06, 2003: Message edited by: Mike Curwen ]
Dear me .. where to start... 1. you are using instance variables like this.request in a servlet - thats a no-no because it is not safe handling multiple requests. 2. if you want a class to represent the browser type, why are you extending HttpServlet? A servlet is meant to live in a servlet engine environment. 3. Why not just a separate class with a constructor that takes the user-agent String, or a setUserAgent method. Bill
Joined: Oct 13, 2003
The init() method isn't called? How is that? Because you didn't call b.init()? Having *just* said that... When I post or GET data doesn't a servlet make an instance of itself? I mean. Why can I not use this?
The servlet container is responsible for instantiating, initializing and destroying a servlet instance. The servlet container, therefore, is what calls the init() method *for you*. You should *not* be treating a servlet as just a "plain old java class". They are highly specialized classes that need a container to run properly.
If you are studying for the SCWCD, I *highly* recommend downloading a copy of the Servlet specification. It has a lot of really good information about servlets, their lifecycle, servlet containers, and the hows and whats of using servlets.