不用ide,编译时遇到下面错误
root@Nodin-OptiPlex-330:/home/fernando/deploy_bed_fbs_linux_ubuntu/tomcat/webapps/register/WEB-INF/classes/app# javac RegisterAction.java
RegisterAction.java:3: 软件包 org.apache.struts.action 不存在
import org.apache.struts.action.*;
^
RegisterAction.java:4: 软件包 javax.servlet.http 不存在
import javax.servlet.http.*;
^
RegisterAction.java:7: 找不到符号
符号: 类 Action
public class RegisterAction extends Action {
^
RegisterAction.java:9: 找不到符号
符号: 类 ActionMapping
位置: 类 app.RegisterAction
public ActionForward perform (ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) {
^
RegisterAction.java:9: 找不到符号
符号: 类 ActionForm
位置: 类 app.RegisterAction
public ActionForward perform (ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) {
^
RegisterAction.java:9: 找不到符号
符号: 类 HttpServletRequest
位置: 类 app.RegisterAction
public ActionForward perform (ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) {
^
RegisterAction.java:9: 找不到符号
符号: 类 HttpServletResponse
位置: 类 app.RegisterAction
public ActionForward perform (ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) {
^
RegisterAction.java:9: 找不到符号
符号: 类 ActionForward
位置: 类 app.RegisterAction
public ActionForward perform (ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) {
^
RegisterAction.java:12: 找不到符号
符号: 类 RegisterForm
位置: 类 app.RegisterAction
RegisterForm rf = (RegisterForm) form;
^
RegisterAction.java:12: 找不到符号
符号: 类 RegisterForm
位置: 类 app.RegisterAction
RegisterForm rf = (RegisterForm) form;
^
RegisterAction.java:21: 找不到符号
符号: 变量 UserDirectory
位置: 类 app.RegisterAction
UserDirectory.getInstance().setUser(username,password1);
^
RegisterAction.java:23: 找不到符号
符号: 类 UserDirectoryException
位置: 类 app.RegisterAction
} catch (UserDirectoryException e) {
^
12 错误
把jar放到同一目录,放到CLASSPATH的目录,都不行
然后用-classpath参数,有点起色。还必须用*.java,否则第二个编译的类RegisterAction.java找不到第一个编译的类RegisterForm,唉唉~,如下:
root@Nodin-OptiPlex-330:/home/fernando/deploy_bed_fbs_linux_ubuntu/tomcat/webapps/register/WEB-INF/classes/app# javac -classpath $CLASSPATH:struts.jar:.:jsp-api-2.0.jar:servlet-api-2.4.jar *.java
RegisterAction.java:21: 找不到符号
符号: 变量 UserDirectory
位置: 类 app.RegisterAction
UserDirectory.getInstance().setUser(username,password1);
^
RegisterAction.java:23: 找不到符号
符号: 类 UserDirectoryException
位置: 类 app.RegisterAction
} catch (UserDirectoryException e) {
^
2 错误
添加UserDirectory类,为了方便去掉了exception
package app;
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 UserDirectoryException {
java.io.InputStream i = null;
p = null;
i = this.getClass().getClassLoader().
getResourceAsStream(UserDirectoryFile);
if (null==i) {
//throw new UserDirectoryException();
}
else {
try {
p = new Properties();
p.load(i);
i.close();
}
catch (java.io.IOException e) {
p = null;
System.out.println(e.getMessage());
//throw new UserDirectoryException();
}
finally {
i = null;
}
} // end else
} // end UserDirectory
/**
*
*/
public static UserDirectory getInstance() {//throws UserDirectoryException {
if (null==userDirectory) {
userDirectory = new UserDirectory();
}
return userDirectory;
}
/**
* Transform id so that it will match any conventions used by user
* directory. The default implementation forces the id to
* uppercase. Does not expect the userId to be null and
* will throw a NPE if it is.
*
* @exception Throws Null Pointer Exception if userId is null.
*/
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 UserDirectoryException {
// no nulls
if ((null==userId) || (null==password)) {
// throw new UserDirectoryException();
}
try {
// conform userId to uppercase when stored
p.put(fixId(userId), password);
p.store(new FileOutputStream(UserDirectoryFile),
UserDirectoryHeader);
}
catch (IOException e) {
//throw new UserDirectoryException();
}
}
} // end UserDirectory
并也简化了RegisterAction.java的exception
package app;
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 UserDirectoryException {
java.io.InputStream i = null;
p = null;
i = this.getClass().getClassLoader().
getResourceAsStream(UserDirectoryFile);
if (null==i) {
//throw new UserDirectoryException();
}
else {
try {
p = new Properties();
p.load(i);
i.close();
}
catch (java.io.IOException e) {
p = null;
System.out.println(e.getMessage());
//throw new UserDirectoryException();
}
finally {
i = null;
}
} // end else
} // end UserDirectory
/**
*
*/
public static UserDirectory getInstance() {//throws UserDirectoryException {
if (null==userDirectory) {
userDirectory = new UserDirectory();
}
return userDirectory;
}
/**
* Transform id so that it will match any conventions used by user
* directory. The default implementation forces the id to
* uppercase. Does not expect the userId to be null and
* will throw a NPE if it is.
*
* @exception Throws Null Pointer Exception if userId is null.
*/
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 UserDirectoryException {
// no nulls
if ((null==userId) || (null==password)) {
// throw new UserDirectoryException();
}
try {
// conform userId to uppercase when stored
p.put(fixId(userId), password);
p.store(new FileOutputStream(UserDirectoryFile),
UserDirectoryHeader);
}
catch (IOException e) {
//throw new UserDirectoryException();
}
}
} // end UserDirectory
遇到如下问题:
File "/WEB-INF/struts-form.tld" not found
根据链接看,是书中的小bug
改下register.jsp就行了
========================================================================================
久坐不利于健康哦!适时起来活动活动吧~
阅读(1463) | 评论(0) | 转发(0) |