actionName!functionName.action
<s:form action="tSlogin!preDate.action" method="post" namespace="/">
距离现在的时间<br/><s:textfield name="time" value="20"/>
<s:select list="listColl" headerKey="-1" headerValue="--学院--"
listKey="id" listValue="college" name="youColl" > </s:select>
<s:submit value="查询"/>
</s:form>
list是一个javaBean的集合 listKey和listValue里面的值只是一个JavaBean的成员变量,
struts2做控制器获取前端参数的方法
三种,第一种是form action写s2的。s2的变量是String 类型的;其余是前端的事情,感觉s2产生大量的代码
第二种是前端写成成员变量的形式user.name,s2写成类变量的形式
第三种是implements ModelDriven,getModel()重写;需要一个javaBean模型,前端写成String类型;
感觉似乎第三种比较好,符合Java面向对象的设计模式
s2内部还可以多写执行方法;但是不符合一个控制器对应一个jsp原则;如果一个jsp来回反复业务;;;
public String prepare() throws Exception
{
listTypes=qDao.listType();
for (int i = 0; i < listTypes.size(); i++) {
Type type=listTypes.get(i);
System.out.println(type.getId()+"--"+type.getName());
}
/*Map session=ActionContext.getContext().getSession();
session.put("listTypes", listTypes);*/
return INPUT;
}
public String add() throws Exception
{
//添加用户 Map
// Map session1=new HashedMap();
Map session=ActionContext.getContext().getSession();
Menber menber=(Menber) session.get("menber");
Integer numberId=menber.getId();
//anserCount是默认值 回答的个数,首先是0
String createTime=new TimeFormat().day();//静态方法
Question question=new Question(createTime,numberId,
this.getTypeId(), this.getTypeKey(), this.getContent(), 0);
//调到输入界面---需要先查询---意思是再次输入问题--不是查看和问答问题
QuestionDao qDao=new QuestionDaoImpl();
qDao.save(question);
//应该跳转到查看界面,不然前端好保存值,
return this.listQue();
}
//查看问题列表
public String listQue() throws Exception
{
QuestionDao qDao=new QuestionDaoImpl();
listQuestion=qDao.listQuestion();
return SUCCESS;
}
总之是调试出来的