🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #2434

deprecated method

#2434
From: Alan Shiers
Date: Wed, 29 Nov 2000 00:00
116 lines
5176 bytes
--------------BC50A21DF76467DD04FDCAD3
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi:
    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)

The entire servlet code goes as follows:
import javax.servlet.*;
import java.io.*;

public class PageBrat extends CoreServlet
{
   public void service(ServletRequest req, ServletResponse res) throws
ServletException, IOException
   {
      res.setContentType("text/html");
      PrintWriter pw = res.getWriter();
      FortuneBrat fb =
(FortuneBrat)getServletContext().getServlet("FortuneBrat");  //<<
getServlet(String s) returns null
      String fortune = fb.getFortune();
      pw.println("Your Fortune: " + fortune);
      pw.close();
   }
}

This servlet references another servlet FortuneBrat.class which compiled
fine. FortuneBrat is set up to simply return a string.

When I look in the javadoc for class ServletContext and check the method
getServlet(String s) it says the following:

getServlet(java.lang.String name)
Deprecated. As of Java Servlet API 2.1, with no direct replacement.
This method was originally defined to retrieve a servlet from a
ServletContext. In this
version, this method always returns null and remains only to preserve
binary compatibility.
This method will be permanently removed in a future version of the Java
Servlet API.

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 criptic for me.  I have no idea what it is telling me or how
I should fix this code for the PageBrat servlet.  Can
someone please explain and show me what I need to do to change the code
to make it work?

Thanks,

Alan


--------------BC50A21DF76467DD04FDCAD3
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Hi:
<br>&nbsp;&nbsp;&nbsp; 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
<br>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
<br>fix.
<br>The method call is from class ServletContext: getServlet(String s)
<p>The entire servlet code goes as follows:
<br>import javax.servlet.*;
<br>import java.io.*;
<p>public class PageBrat extends CoreServlet
<br>{
<br>&nbsp;&nbsp; public void service(ServletRequest req, ServletResponse
res) throws ServletException, IOException
<br>&nbsp;&nbsp; {
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; res.setContentType("text/html");
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PrintWriter pw = res.getWriter();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FortuneBrat fb = (FortuneBrat)getServletContext().getServlet("FortuneBrat");&nbsp;
//&lt;&lt; getServlet(String s) returns null
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String fortune = fb.getFortune();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pw.println("Your Fortune: " + fortune);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pw.close();
<br>&nbsp;&nbsp; }
<br>}
<p>This servlet references another servlet FortuneBrat.class which compiled
fine. FortuneBrat is set up to simply return a string.
<p>When I look in the javadoc for class ServletContext and check the method
getServlet(String s) it says the following:
<p><i>getServlet(java.lang.String name)</i>
<br><i>Deprecated. As of Java Servlet API 2.1, with no direct replacement.</i><i></i>
<p><i>This method was originally defined to retrieve a servlet from a ServletContext.
In this</i>
<br><i>version, this method always returns null and remains only to preserve
binary compatibility.</i>
<br><i>This method will be permanently removed in a future version of the
Java Servlet API.</i><i></i>
<p><i>In lieu of this method, servlets can share information using the
ServletContext class and can perform shared business</i>
<br><i>logic by invoking methods on common non-servlet classes.</i>
<p>This is too criptic for me.&nbsp; I have no idea what it is telling
me or how I should fix this code for the PageBrat servlet.&nbsp; Can
<br>someone please explain and show me what I need to do to change the
code to make it work?
<p>Thanks,
<p>Alan
<br>&nbsp;</html>

--------------BC50A21DF76467DD04FDCAD3--
Technical Details
Message-ID: <3A255571.66E8A8B1@hfx.eastlink.ca>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,dfa9fedc3f5943c2,start
X-Google-Attributes: gid1089d0,public
From: Alan Shiers <jshiers@hfx.eastlink.ca>
Subject: deprecated method
Date: 2000/11/29
Message-ID: <3A255571.66E8A8B1@hfx.eastlink.ca>
X-Deja-AN: 699196545
X-Accept-Language: en
Content-Type: multipart/alternative; boundary="------------BC50A21DF76467DD04FDCAD3"
X-Trace: 29 Nov 2000 10:15:23 -0800, 24.222.107.5
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.java.api