myeclipse 开发struts(三)
来源:互联网 发布:什么是大非农数据 编辑:程序博客网 时间:2024/05/22 03:36
建立一个FORM,为了很好的理解struts 我们不用eclipse来自动生成 我们手写代码!(当然参考了struts in action)
首先建立一个form:
我们只想建立一个欢迎页面 在password 输入 www并提交后页面跳转到一个成功页面(这应用也太简陋了点。。。)
建立FORM:
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
/**
* MyEclipse Struts
* Creation date: 04-04-2009
*
* XDoclet definition:
* @struts.form name="lianxiForm"
*/
public class LianxiForm extends ActionForm {
/*
* Generated fields
*/
/** password property */
private String password;
/** username property */
private String username;
/*
* Generated Methods
*/
/**
* Method validate
* @param mapping
* @param request
* @return ActionErrors
*/
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
return null;
}
/**
* Method reset
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub
}
/**
* Returns the password.
* @return String
*/
public String getPassword() {
return password;
}
/**
* Set the password.
* @param password The password to set
*/
public void setPassword(String password) {
this.password = password;
}
/**
* Returns the username.
* @return String
*/
public String getUsername() {
return username;
}
/**
* Set the username.
* @param username The username to set
*/
public void setUsername(String username) {
this.username = username;
}
}
我没有给出package 建立类可以使用myeclips自动建立
建立后就去strus-config.xml里面配置这个form:
<form-bean name="lianxiForm" type="com.yourcompany.struts.LianxiForm" />
注意name属性的命名 在后面我们会用到.
form建好后在建action。:
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.yourcompany.struts.LianxiForm;
public class LianxiAction extends Action{
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest req,
HttpServletResponse res){
LianxiForm rf = (LianxiForm) form;
String username = rf.getUsername();
String password = rf.getPassword();
ActionForward forward = new ActionForward();
if (password.equals("www")) {
forward = mapping.findForward("success");
}
else{
forward = mapping.findForward("failure");
}
return (forward);
}
}
逻辑有点过于简单了..但是用于练习就不管那么多了
注意 里面的两个参数
success 和failure 这是两个forward 我们也会用到的。
- myeclipse 开发struts(三)
- MyEclipse应用程序开发系列之三:Struts
- MyEclipse应用程序开发系列之三:Struts
- myeclipse 开发struts(四)
- MyEclipse开发Struts实例
- 用MyEclipse开发struts
- MyEclipse应用程序开发系列之三:MyEclipse+struts+Hibernate配置开发
- Struts(3)使用MyEclipse工具开发Struts
- 使用myeclipse轻松开发开发struts项目(英文原版)
- 使用myeclipse开发struts程序
- myEclipse开发Struts的问题
- MyEclipse+struts+Hibernate配置开发
- MyEclipse+struts+Hibernate配置开发
- MyEclipse+struts+Hibernate配置开发
- MyEclipse+struts+Hibernate配置开发
- MyEclipse+struts+Hibernate配置开发
- MyEclipse+struts+Hibernate配置开发
- MyEclipse+struts+Hibernate配置开发
- 极限编程与敏捷开发
- javascript 数组使用
- dr.com 802.1x for linux(Ubuntu)
- SWF文件结构分析
- 全面认识敏捷建模思想(1)
- myeclipse 开发struts(三)
- 对话框中的消息函数
- 金币问题
- 小宝语录
- 又一个发现,大家分享
- 几个正在进行的数据挖掘竞赛
- Java基础知识总结(1)
- 测试贴
- Struts2 简介