Hi
getTable is a method of the class PreReadError. An instance of the class
PreReadError can only use getTable() method.
But in your servlet, you are calling the getTable method with the
instance of a String errorFile. You have to use it as follows
readFile.getTable("Error0").
Thanks & Regards
Balasubramaniyan Krithivasan
-----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 7:18 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