锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
Path=D:\j2sdk1.4.2_03;D:\j2sdk1.4.2_03\bin
CLASSPATH=.;D:\j2sdk1.4.2_03\lib\tools.jar;D:\j2sdk1.4.2_03\lib\dt.jar;D:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar;D:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\jsp-api.jar
聽
// no nulls
if ((null==userId) || (null==password)) {
System.out.print("userid is null");
throw new UserDirectoryException();
}
try {
// conform userId to uppercase when stored
p.put(fixId(userId), password);
String o = this.getClass().getClassLoader().getResource(UserDirectoryFile).getFile();
p.store(new FileOutputStream(o), UserDirectoryHeader);
}
catch (IOException e) {
throw new UserDirectoryException();
}
}
淇敼涓猴細
public void setUser(String userId, String password) throws
UserDirectoryException {
// no nulls
if ((null==userId) || (null==password)) {
System.out.print("userid is null");
throw new UserDirectoryException();
}
try {
// conform userId to uppercase when stored
p.put(fixId(userId), password);
String o = this.getClass().getClassLoader().getResource(UserDirectoryFile).getFile();
System.out.println(o); //o is /D:/myregister/WEB-INF/classes/resources/users.properties
String ostr=o.substring(1); // the line must be add is to use to remove the "/" in String o
System.out.println(ostr); //ostr is D:/myregister/WEB-INF/classes/resources/users.properties
p.store(new FileOutputStream(ostr), UserDirectoryHeader);//modify o as ostr
}
catch (IOException e) {
throw new UserDirectoryException();
}
}
娉ㄦ剰鏈鍏抽敭鐨勬槸灝嗭細this.getClass().getClassLoader().getResource(UserDirectoryFile).getFile();鎵鑾峰緱鐨勫瓧絎︿覆榪涜澶勭悊鍥犱負瀹冨墠闈㈠浜嗕竴涓?/"銆傞渶瑕佸幓鎺夈?BR>
鑻辨枃錛?BR>
I found a solution to your problem
first step:
you must deploy the application build a folder make sure you don't use
a directory which has any spaces in the path (such as the Program Files directory on Windows)as this may
cause the UserDirectoryException.
such as build a folder "myregister" in Driver D and copy the program in it.
add the following codes to server.xml:
<Context path="/myregister"
docBase="d:\myregister\"
crossContext="false"
debug="0"
reloadable="true" >
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_dbtest_log." suffix=".txt"
timestamp="true"/>
</Context>
second step:
just find the following code within the 'UserDirectory.java'
public void setUser(String userId, String password) throws
UserDirectoryException {
// no nulls
if ((null==userId) || (null==password)) {
System.out.print("userid is null");
throw new UserDirectoryException();
}
try {
// conform userId to uppercase when stored
p.put(fixId(userId), password);
String o = this.getClass().getClassLoader().getResource(UserDirectoryFile).getFile();
p.store(new FileOutputStream(o), UserDirectoryHeader);
}
catch (IOException e) {
throw new UserDirectoryException();
}
}
modify as follow:
public void setUser(String userId, String password) throws
UserDirectoryException {
// no nulls
if ((null==userId) || (null==password)) {
System.out.print("userid is null");
throw new UserDirectoryException();
}
try {
// conform userId to uppercase when stored
p.put(fixId(userId), password);
String o = this.getClass().getClassLoader().getResource(UserDirectoryFile).getFile();
System.out.println(o); //o is /D:/myregister/WEB-INF/classes/resources/users.properties
String ostr=o.substring(1); // the line must be add is to use to remove the "/" in String o
System.out.println(ostr); //ostr is D:/myregister/WEB-INF/classes/resources/users.properties
p.store(new FileOutputStream(ostr), UserDirectoryHeader);//modify o as ostr
}
catch (IOException e) {
throw new UserDirectoryException();
}
}
by the way,the String o is /D:/myregister/WEB-INF/classes/resources/users.properties
the String ostr is D:/myregister/WEB-INF/classes/resources/users.properties