Struts2 select标签如何获取action中传来的值进行option选择? 本帖最后由 zhangdong2009 于 2010-04-14 16:38:27 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 package model.exam.action.exam;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.servlet.http.HttpServletRequest;import model.exam.entity.Examination;import model.exam.service.ExamService;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;@SuppressWarnings("serial")public class ModifyExamAction extends ActionSupport { private HttpServletRequest req; private Examination exam ; private String id; private String type; private ExamService examService; public ExamService getExamService() { return examService; } public void setExamService(ExamService examService) { this.examService = examService; } @SuppressWarnings("unchecked") @Override public String execute() throws Exception { req = ServletActionContext.getRequest(); Map request = (Map) ActionContext.getContext().get("request"); id = req.getParameter("tno"); type = req.getParameter("type"); List<Examination> list5 = this.examService.findById(id); exam=list5.get(0); Integer degreeno=null;//记录难度编号 Integer typeno=null;//记录试题类型编号 /*计算试题类型*/ if(exam.getType().equals("选择题"))typeno=1; if(exam.getType().equals("填空题"))typeno=2; if(exam.getType().equals("判断题"))typeno=3; if(exam.getType().equals("问答题"))typeno=4; if(exam.getType().equals("运算题"))typeno=5; /*计算难度类型*/ if(exam.getTdegree().equals("容易"))degreeno=1; if(exam.getTdegree().equals("较容易"))degreeno=2; if(exam.getTdegree().equals("中等"))degreeno=3; if(exam.getTdegree().equals("较难"))degreeno=4; if(exam.getTdegree().equals("很难"))degreeno=5; //存储试题类型MAP Map map=new HashMap(); map.put(1, "选择题"); map.put(2, "填空题"); map.put(3, "判断题"); map.put(4, "问答题"); map.put(5, "运算题"); //存储试题难度MAP Map degreemap=new HashMap(); degreemap.put(1, "容易"); degreemap.put(2, "较容易"); degreemap.put(3, "中等"); degreemap.put(4, "较难"); degreemap.put(5, "很难"); request.put("degreeno", degreeno); request.put("degreemap", degreemap); request.put("typeno", typeno); request.put("map", map); request.put("exam", exam); if (type.equals("1")) { return "success2"; } else { return "success"; } }}这是我的action 1.jsp写法:<s:select list="#request.degreemap" name="degreeno"></s:select>2.设置数据:req.setAttribut("degreeno", degreeno);req.setAttribut("degreemap", degreemap); req.setAttribute("degreeno", degreeno);req.setAttribute("degreemap", degreemap); 没有说到重点问题上,我是想知道从一个action中获取了表中一个字段的值.这个值是类型变量(它有五个值),现在我要在页面上展示表中选择的值在表单select标签中对应显示出来 <s:select list="#request.degreemap" name="degreeno"> <s:iterator test="="#request.degreemap"> ... </s:iterator></s:select>这样可以吗 建议LZ用下DWR 非常简单的 非常好用! 一个service方法中两个并列的更新方法,如何保证数据同时回滚 proguard有没有这样的功能 struts s:token 使用有问题,请教各位大仙!!! struts1 文章获取和保存的代码 PreparedStatement 问题! jar包运行时的找不到hibernate的映射问题,难度不小! dwr参数为List时报错 还是那个struts的问题,但问题发生了变化,很奇怪,页面没有做转向,在线等!!! JTable行选取的问题 关于数组越界的问题 如何在控制台编译servlet类 如何开始项目开发
import java.util.List;
import java.util.Map;import javax.servlet.http.HttpServletRequest;import model.exam.entity.Examination;
import model.exam.service.ExamService;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
public class ModifyExamAction extends ActionSupport
{
private HttpServletRequest req;
private Examination exam ; private String id;
private String type; private ExamService examService; public ExamService getExamService() {
return examService;
} public void setExamService(ExamService examService) {
this.examService = examService;
} @SuppressWarnings("unchecked")
@Override
public String execute() throws Exception {
req = ServletActionContext.getRequest();
Map request = (Map) ActionContext.getContext().get("request");
id = req.getParameter("tno");
type = req.getParameter("type");
List<Examination> list5 = this.examService.findById(id);
exam=list5.get(0);
Integer degreeno=null;//记录难度编号
Integer typeno=null;//记录试题类型编号
/*计算试题类型*/
if(exam.getType().equals("选择题"))typeno=1;
if(exam.getType().equals("填空题"))typeno=2;
if(exam.getType().equals("判断题"))typeno=3;
if(exam.getType().equals("问答题"))typeno=4;
if(exam.getType().equals("运算题"))typeno=5;
/*计算难度类型*/
if(exam.getTdegree().equals("容易"))degreeno=1;
if(exam.getTdegree().equals("较容易"))degreeno=2;
if(exam.getTdegree().equals("中等"))degreeno=3;
if(exam.getTdegree().equals("较难"))degreeno=4;
if(exam.getTdegree().equals("很难"))degreeno=5;
//存储试题类型MAP
Map map=new HashMap();
map.put(1, "选择题");
map.put(2, "填空题");
map.put(3, "判断题");
map.put(4, "问答题");
map.put(5, "运算题");
//存储试题难度MAP
Map degreemap=new HashMap();
degreemap.put(1, "容易");
degreemap.put(2, "较容易");
degreemap.put(3, "中等");
degreemap.put(4, "较难");
degreemap.put(5, "很难");
request.put("degreeno", degreeno);
request.put("degreemap", degreemap);
request.put("typeno", typeno);
request.put("map", map);
request.put("exam", exam);
if (type.equals("1")) {
return "success2";
} else {
return "success";
}
}}
这是我的action
<s:select list="#request.degreemap" name="degreeno">
</s:select>2.设置数据:
req.setAttribut("degreeno", degreeno);
req.setAttribut("degreemap", degreemap);
req.setAttribute("degreemap", degreemap);
<s:iterator test="="#request.degreemap">
...
</s:iterator>
</s:select>这样可以吗 建议LZ用下DWR 非常简单的 非常好用!