发布应用:
发布后:
增加一个类,如下:但是是啥作用可能需要你仔细研究了 这个应用啥参考刘铁手的 struts in action 做出来的 他没有给出代码,下述代码是我在网上查到的:
package com.yourcompany.struts;
import java.io.IOException;
//import java.io.InputStream;
import java.io.FileOutputStream;
import java.util.Enumeration;
import java.util.Properties;
public class UserDirectory {
private static final String UserDirectoryFile = "resources/users.properties";
private static final String UserDirectoryHeader = "${user}=${password}";
private static UserDirectory userDirectory = null;
private static Properties p;
private UserDirectory() throws Exception {
java.io.InputStream i = null;
p = null;
i = this.getClass().getClassLoader().
getResourceAsStream(UserDirectoryFile);
if (null==i) {
throw new Exception();
}
else {
try {
p = new Properties();
p.load(i);
i.close();
}
catch (java.io.IOException e) {
p = null;
System.out.println(e.getMessage());
throw new Exception();
}
finally {
i = null;
}
} // end else
} // end UserDirectory
public static UserDirectory getInstance() throws
Exception {
if (null==userDirectory) {
userDirectory = new UserDirectory();
}
return userDirectory;
}
public String fixId(String userId) {
return userId.toUpperCase();
}
public boolean isValidPassword(String userId, String
password) {
// no null passwords
if (null==password) return false;
// conform userId to uppercase
String _userId = fixId(userId);
// no passwords for non-users
if (!isUserExist(_userId)) return false;
// does password match user's password
return (password.equals(getPassword(_userId)));
}
public boolean isUserExist(String userId) {
// no null users
if (null==userId) return false;
// if not null, it's a user
return !(null==p.getProperty(userId));
}
public String getPassword(String userId) {
return p.getProperty(userId);
}
public Enumeration getUserIds() {
return p.propertyNames();
}
public void setUser(String userId, String password)
throws
Exception {
// no nulls
if ((null==userId) || (null==password)) {
throw new Exception();
}
try {
// conform userId to uppercase when stored
p.put(fixId(userId), password);
p.store(new FileOutputStream(UserDirectoryFile),
UserDirectoryHeader);
}
catch (IOException e) {
throw new Exception();
}
}
} // end UserDirectory