Well, you're sort of right.  The init method only get's called once, but you
won't have a request/response pair to attach that session object to.  You
can, however, create private members to hold that information, something
like:

public class Foo extends HttpServlet {
  private Properties props;

  public Foo () {
    props = new Properties();
  }

  public init (ServletConfig cfg) {
    super(cfg);
    props.read(new FileInputStream("myconfig.properties"));
  }

  public void doGet (HttpServletRequest req,HttpServletResponse res) {
    String key;
    PrintWriter out = new PrintWriter(res.getWriter());
    out.println("<H1>My Properties</H1>");
    out.println("<TABLE BORDER=1>");
    out.println("  <TR>");
    out.println("    <TH>Key</TH>");
    out.println("    <TH>Value</TH>");
    out.println("  </TR>");
    Enumeration enum = props.propertyNames();
    while(enum.hasMoreElements()) {
      out.println("  <TR>");
      key = (String)enum.nextElement();
      out.println("    <TD>" + key + "</TD>");
      out.println("    <TD>" + props.getProperty(key) + "</TD>");
      out.println("  </TR>");
    }
    out.println("</TABLE>");
    out.close();
  }

}

(*Chris*)

----- Original Message -----
From: Jaman Burton <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, April 13, 1999 7:45 AM
Subject: Am I understanding this correctly?


>      If I place code in my servlet init() that reads 5 lines from an .ini
>      file and saves that data as 5 strings, let's call the line1, line2,
>      line3, line4, line5.
>
>      Then if I am understanding this correctly, those 5 "line" variables
>      are placed in memory and subsequent calls to that servlet does not
>      call init().
>
>      Therefore, if in my service() method of the same servlet I do
>      something like session.putValue("Param1",line1);  Every user that
>      accesses that servlet will get the same values placed in thier
session
>      variable for those 5 "line" variables, but only the first person to
>      request the servlet will actually call the init() method.
>
>      Is that correct?
>
>
>      Jaman Burton
>      [EMAIL PROTECTED]
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to