I have tested this problem on both tomcat-3.2.2 and tomcat-4.0-b3.
Here is a jsp that works just fine.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page language="java" session="true" %>
<%@ page import="java.io.*,java.util.*" %>
<html>
  <head>
    <title>Test</title>
  </head>

  <body bgcolor="white">
    <h1>Test</h1>
    
<%
    Properties props = new Properties();
    InputStream is = null;
    try {
       is = getServletContext().getResourceAsStream("/WEB-INF/easMail.properties");
    } catch ( Exception ex ) {
        out.print("ResourceAsStream problem:" + ex.getMessage());
    }   
    try {
      props.load(is);
    } catch ( java.io.IOException e ) {
      out.print("Can't load the properties file");
    }
    for (Enumeration e = props.propertyNames(); e.hasMoreElements();) {
        String pn = (String)e.nextElement();
        out.print(pn + ": " + props.getProperty(pn) + "<br>");
    }
%>
    <hr>
    <address><a href="mailto:[EMAIL PROTECTED]";>Earl Stutes</a></address>
<!-- Created: Mon Apr 16 15:34:31 PDT 2001 -->
<!-- hhmts start -->
Last modified: Mon Apr 23 18:29:11 PDT 2001
<!-- hhmts end -->
  </body>
</html>

Here is its output

Test
mail.imap.socketFactory.class: javax.net.ssl.SSLSocketFactory
mail.transport.protocol: smtp
mail.imap.socketFactory.port: 993
mail.imap.socketFactory.fallback: false
mail.store.protocol: imap


Here is a snippet of code from my servlet.
line #
124  private void doTask() throws ServletException,IOException,
125                              EasMailException {
126     ssn = request.getSession(true);
127     String task = request.getParameter("task");
128     InputStream is = null;
129     try {
130            is = 
getServletContext().getResourceAsStream("/WEB-INF/easMail.Properties");
131     }
        catch (Exception ex) {
            request.setAttribute("javax.servlet.jsp.jspException", ex);
            svcxt.getRequestDispatcher("/Error.jsp").forward(request, response);
        }           
        try {
            props.load(is);
        }
        catch (Exception ex) {
            throw  new ServletException( "can't find properties file: " + 
ex.getMessage());
        }

Here is the results from running the servlet.

Error Encountered.

java.lang.NullPointerException

java.lang.NullPointerException 
at javax.servlet.GenericServlet.getServletContext(GenericServlet.java:205)
at easMail.easMailServlet.doTask(easMailServlet.java:130)
at easMail.easMailServlet.doPost(easMailServlet.java:96)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

What is wrong with this picture? Originally I had the code inside my
init() method, but moved it down in the main body of the class to see
if I was doing something wrong in the init() code.

Thanks

=eas=


Reply via email to