站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Eclipse 专题谁能教我在action中写方法

谁能教我在action中写方法

摘要: 谁能教我在action中写方法


我想在action中写一个方法,将一段重复的代码放在一方法中;
if(graduate.equals("01"))
{
list=db.find("select distinct userno from Learning where graduate='"+s2+"'");
for (int i=0;i {
String userno1=(String)list.get(i);
list1=db.find("from Learning where userno='"+userno1+"' and graduate='"+s2+"' order by startdate desc");
Learning ln=(Learning)list1.get(0);
array.add(i,ln);
}
//session.setAttribute(Constants.LEARNING_DISPLAY_KEY,array);
}
}
else if(condition.equals("02"))
{
list=db.find("select distinct userno from Learning ");
for (int i=0;i {
String userno1=(String)list.get(i);
list1=db.find("from Learning where userno='"+userno1+"' order by startdate desc");
Learning ln=(Learning)list1.get(0);
array.add(i,ln);
}

}
session.setAttribute(Constants.LEARNING_DISPLAY_KEY,array);
我想把for循环的代码放在一个方法中我应该怎么写好呢


action中除了execute不能有其他方法的


对,你可以调用其他的class,将重复代码放在那里去


怎么调用其他的class


你的action只要继承DispatchAction,你就可以写自己的方法了。而且他不会调用exceute这个方法了。而是调用你页面里的那个action里的参数!!!!!


就没有人帮我写一个action?


当菜鸟真不容易!


可以把方法写在内部类里,我做过


还是不太明白


public class Ph000Action extends Action {
ArrayList list;
/**
* Method execute
* @param ActionMapping mapping
* @param ActionForm form
* @param HttpServletRequest request
* @param HttpServletResponse response
* @return ActionForward
* @throws Exception
*/
synchronized public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
list = //获取的数据

ModFor(list);

return mapping.findForward(strForward);
}

/**
* init. subClass must inherit
*/
public void ModFor(ArrayList list) {
//Add Method
}

}



↑返回目录
前一篇: eclipse的编辑窗体中如何才能显示多行标签?
后一篇: 怎么截取年的后2位?