本帖最后由 zhangdong2009 于 2010-04-14 16:38:27 编辑

解决方案 »

  1.   

    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
      

  2.   

    1.jsp写法:
    <s:select list="#request.degreemap" name="degreeno">
    </s:select>2.设置数据:
    req.setAttribut("degreeno", degreeno);
    req.setAttribut("degreemap", degreemap);
      

  3.   

    req.setAttribute("degreeno", degreeno);
    req.setAttribute("degreemap", degreemap);
      

  4.   

    没有说到重点问题上,我是想知道从一个action中获取了表中一个字段的值.这个值是类型变量(它有五个值),现在我要在页面上展示表中选择的值在表单select标签中对应显示出来
      

  5.   

    <s:select list="#request.degreemap" name="degreeno">
      <s:iterator test="="#request.degreemap">
         ...
      </s:iterator>
    </s:select>这样可以吗 建议LZ用下DWR 非常简单的 非常好用!