hai,

Problems identified:

1. In PreReadError.java the scope of the table variable is with in the
constructor only.
2. if you try to access the getTable method the Hashtable variable table
give an compilation error that undefined error.
3. May be the package structure problem check the servlet and
PreReadError.java are in same working directory or not? If not import the
preReadError.java in GetUserIdentity.java.
4. str=(String )errorfile.getTable("Error0"); replace errorfile with
readfile because readfile is holding the instances of the PreReadError.java

        After these modifications I think this application will work.

bye..
have a nice day


-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet API
Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of Edward
Sent: Wednesday, May 29, 2002 11:48 AM
To: [EMAIL PROTECTED]
Subject: How to create context in servlet?
Importance: High


   I have a Hash table,I want to place it into context of a servlet,so this
Hash table can be called by any users.My Hash table file named
"PreReadError.java",it is follows:
 public class PreReadError
{
   public PreReadError()
  {
     Hashtable table=new Hashtable();
      table.put("Error0","Error");
      table.put("Error1","Redirect");
  }

  public String getTable(String str)
 {
  String result=(String) table.get(str);
  return result;
 }
}


My servlet file named "GetUserIdentity.java" is follows:

import javax.servlet.ServletContext;
public class GetUserIdentity extends HttpServlet
{
  PreReadError readfile;
  String errorfile;
  String str;
  ServletContext context;

  public GetUserIdentity()
 {
    context=getServletContext();
 }

 public void doPost(HttpServletRequest request,HttpServletResponse response)
     throws ServletException,IOException
 {
    //Here,I want to create a context if it is not exist,else call it's
method directly
    if(context.getAttribute("errorfile")==null)
    {
       readfile=new PreReadError();
       context.setAttribute(errorfile,readfile);
    }
    str=(String )errorfile.getTable("Error0");
    System.out.println("Message is:"+str);
  }
 }
}

When I compile it,it raise a error,it follows:

F:\login\ejb>javac -classpath .;f:\j2sdkee1.3.1\lib\j2ee.jar
GetUserIdentity.java

GetUserIdentity.java:55: cannot resolve symbol
symbol  : method getTable  (java.lang.String)
location: class java.lang.String
                        str=(String )errorfile.getTable("Error0");
                                              ^
1 error

I don't know how to put my Hashtable into a servlet and how to call it's
methods?
Any idea will be appreciated!
Thanks in advance.
Edward

___________________________________________________________________________
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