you should call the super(config) inside the init(ServletConfig....)
method,
which i think does the work well!
ks
-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 03, 2001 1:51 AM
To: [EMAIL PROTECTED]
Subject: Re: variable set in init is null in doPost
What if you try overiding the following method instead
init(ServletConfig config)
> -----Original Message-----
> From: A mailing list for discussion about Sun Microsystem's Java Servlet
> API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of Gerry
> Scheetz
> Sent: Monday, April 02, 2001 1:09 PM
> To: [EMAIL PROTECTED]
> Subject: variable set in init is null in doPost
>
>
> In my init procedure I am initializing a hash table, but when I
> try to access the data from that hash table in my doPost method,
> the table value is null. Below is my code and right now I get
> the following error.
>
> [02/04/2001 14:05:40:005 MDT] ChildCare/ChildCare.servlets.ChildCare:
init
> [02/04/2001 14:05:40:015 MDT] javax.servlet.ServletException:
> Actions is null
> at ChildCare.servlets.ChildCare.doPost(ChildCare.java:64)
> at ChildCare.servlets.ChildCare.doGet(ChildCare.java:37)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:499)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:588)
> at
> org.apache.jserv.JServConnection.processRequest(JServConnection.java)
> at org.apache.jserv.JServConnection.run(JServConnection.java)
> at java.lang.Thread.run(Thread.java:479)
>
> If I take out the
> if (actions == null)
> throw new ServletException("Actions is null");
> code, I get a null pointer exception on the next line of code.
>
> I am using Apache/JServ. Any help is appreciated, especially
> advise on how to debug this problem on my own in the future.
>
> package ChildCare.servlets;
>
> import java.net.*;
> import java.sql.*;
> import javax.sql.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import java.io.*;
> import java.util.*;
> import ChildCare.MenuItem;
> import ChildCare.beans.provider.*;
>
> public class ChildCare extends HttpServlet {
> private Hashtable actions;
> private LinkedList inquiryMenu;
>
> /**
> * Creates the application scope objects used by the Actions
> * and JSP pages in this application.
> */
> public void init() throws ServletException {
> initActions();
> }
>
> /**
> * Cleans up before stopping servlet
> */
> public void destroy() {
> }
>
> /**
> * Performs the same processing as for a POST request.
> */
> public void doGet(HttpServletRequest request,
> HttpServletResponse response)
> throws IOException, ServletException {
> doPost(request, response);
> }
>
> /**
> * Locates the Action object corresponding to the requested
> * action, or the start Action in case the user is not yet
> * authenticated, and dispatch the processing to the selected
> * Action object.
> */
> public void doPost(HttpServletRequest request,
> HttpServletResponse response)
> throws IOException, ServletException {
>
> String nextURL = null;
>
> try {
> String actionName = request.getParameter("action");
>
> // Use the login action if the user is not authenticated
> if (actionName == null ||
> (!isAuthenticated(request) &&
> (!"authenticate".equals(actionName) ||
> "signout".equals(actionName)))) {
> actionName = "start";
> }
>
> if (actions == null)
> throw new ServletException("Actions is null");
>
> Action action = (Action) actions.get(actionName);
>
> nextURL = action.perform(this, request, response);
> }
> catch (ActionException e) {}
> RequestDispatcher rd = request.getRequestDispatcher(nextURL);
> rd.forward(request, response);
>
> }
>
> /**
> * Returns true if the session contains the authentication token.
> */
> private boolean isAuthenticated(HttpServletRequest request) {
> boolean isAuthenticated = false;
>
> HttpSession session = request.getSession(true);
> if (session.getAttribute("validUser") != null) {
> isAuthenticated = true;
> }
> return isAuthenticated;
> }
>
> /**
> * Initializes the set of Action objects used by the
> * application. Instead of hardcoding this list, it can
> * be based on configuration information, such as
> * servlet initialization parameters.
> */
> private void initActions() {
> actions = new Hashtable();
> actions.put("start",
> new NullAction("start.jsp?message=" +
> URLEncoder.encode("Please sign on first!")));
> actions.put("authenticate", new AuthenticateAction("menu.jsp"));
> actions.put("help", new NullAction("help.jsp"));
> actions.put("menu", new NullAction("menu.jsp"));
> actions.put("chg_password", new NullAction("change_password.jsp"));
> actions.put("inquiry", new NullAction("inquiry.jsp"));
> actions.put("inquiry_list", new NullAction("inquiry_list.jsp"));
> actions.put("signout", new SignOutAction("signon.jsp"));
>
> .
> .
> .
> }
>
> /**
> * Get Servlet information
> * @return java.lang.String
> */
> public String getServletInfo() {
> return "ChildCare.Core.ChildCare Information";
> }
> }
>
>
> Gerry Scheetz
> Web Application Development
> Global Information Technology Division
> TRW - S&ITG
> Helena, Montana, USA
> [EMAIL PROTECTED]
> (406) 594-1878
>
> __________________________________________________________________
> _________
> 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
___________________________________________________________________________
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