struts中的helper类的简单使用问题。 help!!!

firedrose 2006-03-18 02:41:43
按教程上的一个Action中如下的代码:

package app;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import java.io.*;
public class RegisterAction extends Action {
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest req,
HttpServletResponse res) {
// ○1 将form 转型为RegisterForm
RegisterForm rf = (RegisterForm) form;
String username = rf.getUsername();
String password1 = rf.getPassword1();
String password2 = rf.getPassword2();
ActionForward forward = new ActionForward();
// ○2 应用业务逻辑
if (password1.equals(password2)) {
try {
// ○3 如成功,则返回针对success 的ActionForward
UserDirectory.getInstance().setUser(username,password1);
forward = mapping.findForward("success");
} catch (UserDirectoryException e) {
forward = mapping.findForward("failure");
}
} else{
forward = mapping.findForward("failure");
}
// ○4 返回针对failure的ActionForward
return (forward);
}
}



在读到UserDirectory时出错了,显示“不能解析UserDirectory,它不是一种类型。”

可是教材上写“如果两次密码匹配○2 ,我们将用户添加到 UserDirectory 中,并返回与success 对应的ActionForward 。UserDirectory 是一个 helper 类,它记录usernames 和passwords 到一个标准的属性文件之中。”

这个helper类要如何加入,要如何设才可以用呢????

...全文
97 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
cenlmmx 2006-03-18
  • 打赏
  • 举报
回复
你去下载一下源代码,里面就有,大概如下:
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 <b>not</b> 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
内容概要:本文围绕可变桨叶四旋翼无人机的规范控制与点对点运动模拟展开,重点研究优化推力分配策略在翻转动作的应用与性能比较。通过Matlab代码实现,构建了四旋翼动力学模型,并设计了多种控制算法以实现精确的姿态调整与轨迹跟踪。研究对比了不同推力分配方案在执行高机动性翻转动作时的稳定性、能耗效率与响应速度,旨在提升无人机在复杂飞行任务的动态性能与控制精度。该仿真研究为无人机飞控系统的设计与优化提供了理论依据和技术支持。; 适合人群:具备一定自动控制理论基础和Matlab编程能力,从事无人机控制、飞行器动力学或机器人系统研究的科研人员及研究生。; 使用场景及目标:① 实现四旋翼无人机在三维空间的精确点对点运动控制;② 对比分析不同推力分配策略在执行翻转等高难度动作时的控制效果与能耗表现,优化飞行性能;③ 为无人机自主飞行、特技飞行及复杂环境下的机动控制提供算法验证平台。; 阅读建议:此资源以Matlab仿真为核心,建议读者结合相关控制理论知识,深入理解代码实现细节,重点关注动力学建模、控制律设计与推力分配模块。在学习过程,应动手调试参数,复现文翻转动作的仿真结果,并尝试拓展至其他复杂飞行任务,以加深对无人机控制机理的理解。

81,111

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧