The first time the Servlet is ever called, the init() method will be invoked. Servlets are shy creatures that just mind their own business, but get a few drinks into them and get them LOADED, and they're the life of the party. One call to init, and they've got a lampshade on their head until the server is taken down.
If the Servlet is invoked by a URL, the get invokation is being called, or the doGet method. It's pretty much the default - clicking a link, typeing a URL into an address bar, clicking a bookmark - that's all get. Even a form submission will default to get if the HTML developer doesn't explicity state method=POST
As far as calling a Servlet by providing the URL and context root and Servlet name: not sure there's any other way to do it. Clients have to get to your Servlet somehow, although an appliation will likely have a relative linking to the Servlet, as opposed to hardcoding everything into it. Of cousre, who accesses a Servlet can be restricted by a security contraint. That's the whole reason for their existence.
Joined: Mar 31, 2005
although an appliation will likely have a relative linking to the Servlet, as opposed to hardcoding everything into it
Is this relative reference to the mapping in a web.xml?
Thanks in advance Regards Zein
PS: the videos in the above link are great, bravo, keep up the good work
Cameron Wallace McKenzie
author and cow tipper
When I was saying a relative linking, I was just talking about the URL, and how an HTML form might invoke the Servlet.
Seriously, there's no fear with people invoking the Servlet directly. In fact, that's what we WANT them to do. Servlets are controllers, and they can implement security, state management, and even flow control, so if someone is invoking a Servlet when they shouldn't be, the Servlet can redirect them somewhere else.
The web.xml file maps an alias name for the Servlet to the actual code for the servlet. So, I might use the url: