Article View: borland.public.jbuilder.java.api
Article #2437Re: deprecated method
From: Alan Shiers
Date: Wed, 29 Nov 2000 00:00
Date: Wed, 29 Nov 2000 00:00
86 lines
3848 bytes
3848 bytes
Hi Paul:
I tried posting to borland.public.jbuilder.servlet newsgroup earlier,
however, I was having technical difficulties. I was able to post to any of
the newsgroups except this one. I kept getting prompted for a user name
and password. Beats me...
At any rate, out of frustration, I posted to this newsgroup, hoping someone
would have an answer to my dilemma. And you did. Thank you very much for
your input.
I'll try out your suggestions.
Alan
"Paul Furbacher [TeamB]" wrote:
> Alan,
>
> This question belongs more properly in the "servlets-jsp" newsgroup.
> But I'll answer it here. (In the future, try harder to post to
> the appropriate newsgroup. Thanks.)
>
> > I'm trying to learn about servlets from a book entitled Core Java
> > Web Server and as I have been following it along with its
> > various code samples I've come accross the code for a servlet which
> > has a deprecated method call that I don't know how to fix.
>
> > The method call is from class ServletContext: getServlet(String s)
> > [...]
> >
> > public void service(ServletRequest req, ServletResponse res)
> > throws ServletException, IOException
> > {
> > res.setContentType("text/html");
> > PrintWriter pw = res.getWriter();
>
> // next line returns "null"
> > FortuneBrat fb =
> > (FortuneBrat)getServletContext().getServlet("FortuneBrat");
> > ...
> >
> > This servlet references another servlet FortuneBrat.class which
> > compiled fine. FortuneBrat is set up to simply return a string.
> >
> > [...]
> > getServlet(java.lang.String name)
> > Deprecated. As of Java Servlet API 2.1, with no direct replacement.
> >
> > [...]
> >
> > In lieu of this method, servlets can share information using the
> > ServletContext class and can perform shared business
> > logic by invoking methods on common non-servlet classes.
> >
> > This is too cr[y]ptic for me. I have no idea what it is
> > telling me or how I should fix this code for the PageBrat
> > servlet.
>
> The "In lieu of..." sentence is awkwardly phrased, no doubt.
> What it means is that instead of invoking a servlet to do this
> work, use a regular Java class. Currently, you have functional code
> in "FortuneBrat" which is being "shared" by a number of servlets
> perhaps -- that's the "servlets can share information [or] business
> logic..." portion of the above awkward sentence. Instead of putting
> the "bp.getFortune()" logic in a servlet, place it in a separate
> (non-servlet) Java class. Either instantiate "FortuneBrat" when you
> need it, or make its "getFortune()" method static:
>
> public class FortuneBrat {
>
> public static String getFortune([parameters?]) {
> String theFortune = "";
> ... // do some processing based on parameters, if any ...
> return theFortune;
> }
>
> }
>
> There are very few reasons why you would want to get a servlet.
> These are pretty much related to administrative functions, and
> not your "run-of-the-mill" request handling. Your requirements
> fall into the latter category.
>
> Paul Furbacher (TeamB)
>
> Please, no private correspondence related to
> newsgroup issues. Thanks.
Technical Details
Message-ID:
<3A25A578.917EBA2D@hfx.eastlink.ca>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3A255571.66E8A8B1@hfx.eastlink.ca> <3A255BD4.4DA72190@home.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,dfa9fedc3f5943c2 X-Google-Attributes: gid1089d0,public From: Alan Shiers <jshiers@hfx.eastlink.ca> Subject: Re: deprecated method Date: 2000/11/29 Message-ID: <3A25A578.917EBA2D@hfx.eastlink.ca> X-Deja-AN: 699320890 Content-Transfer-Encoding: 7bit References: <3A255571.66E8A8B1@hfx.eastlink.ca> <3A255BD4.4DA72190@home.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Trace: 29 Nov 2000 15:56:51 -0800, 24.222.107.5 MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.api