Hi Edward,
I believe the compiler error is due to the fact that it can't determine
the
class of the errorfile object at compile time.
Try this syntax :
str=3D(String )(((PreReadError)errorfile).getTable("Error0"));
Cheers,
JeanLuc
-----Message d'origine-----
De?: Edward [mailto:zhangsc@n...]
Envoy=A8=A6?: mercredi 29 mai 2002 08:20
=A8=A4?: Java 2 Enterprise Edition
Objet?: [j2ee] How to create context in servlet?
Importance?: Haute
I have a question about create context in servlet,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=3Dnew Hashtable();
table.put("Error0","Error");
table.put("Error1","Redirect");
}
public String getTable(String str)
{
String result=3D(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=3DgetServletContext();
}
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")=3D=3Dnull)
{
readfile=3Dnew PreReadError();
context.setAttribute(errorfile,readfile);
}
str=3D(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=3D(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