急??一个struts 的问题

06-03-30 wuliugenghutin
我在jsp表单中动态的显示了一系列radio单选按钮,在提交时值已传入到formbean但在action中提取值时是空的以下是我的jsp代码

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@ taglib uri="struts-bean" prefix="bean" %>

<%@ taglib uri="struts-html" prefix="html" %>

<%@ taglib uri="struts-logic" prefix="logic" %>

<%@ taglib uri="teach" prefix="teach"%>

<%@ page import="com.teachmanage.util.javabeans.MyUtility" %>

<%@ page import="java.util.*" %>

<%

String contextPath = request.getContextPath();

String confirmMsg = MyUtility.getMessage("label.delete.Confirm");

ArrayList assesslist=(ArrayList)session.getAttribute("AssessNoList");

int leng=assesslist.size();

String assesno[]=new String[leng];

int id[]=new int[leng];

for(int j=0;j<leng;j++){

assesno[j]=(String)assesslist.get(j);

id[j]=Integer.parseInt(assesno[j]);

}

int i=0;

//String temp="";

int k=0;

out.print(leng);

%>

<html:html>

<HEAD>

<TITLE>

<bean:message key="Teach.title"/>

<html:base/>

</TITLE>

<script language="javaScript">

function back(){

document.form2.strutsAction.value="0";

document.form2.action="/teachmanager/person/assess.do";

document.form2.submit();

}

function submitScore(){

alert("dd");

document.form2.strutsAction.value="4";

document.form2.submit();

}

</script>

<META content="text/html; charset=utf-8" http-equiv=Content-Type><LINK

href="<%=contextPath%>/css/pub.css" rel=stylesheet type=TEXT/CSS>

<META content="MSHTML 5.00.3819.300" name=GENERATOR>

</HEAD>

<body leftMargin=0 topMargin=0 MARGINheight="0" MARGINwidth="0">

<teach:menu/>

<table>

<tr >

<td vAlign=top>

<%@ include file="../side.jsp"%>

</td>

<html:form name="form2" action="/student/assesslist" type="com.teachmanage.assess.javabeans.AssessForm">

<html:hidden property="strutsAction"/>

<html:hidden property="teachName"/>

<html:hidden property="pagerOffSet"/>

<TD vAlign="top" align="left" width=100%>

<TABLE border=0 cellPadding=0 cellSpacing=0 width=90% align="center">

<TR>

<TD><B><FONT color=#835CA2>学生考评管理</FONT></B><IMG border=0

src="<%=contextPath%>/images/arrow.gif">

</TD>

<TD align=right><A

href="javascript:this.location.reload();">刷新</A>

</TD>

</TR>

<TR bgColor=#000000>

<TD colSpan=2><IMG alt="" border=0 height=1

src="<%=contextPath%>/images/dot(1).gif" width=1>

</TD>

</TR>

</TABLE>

<br>

<br>

<br>

<logic:present name="AssessList">

<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0" class="Detail-Table-Bigest">

<tr>

<td width="8" height="8"><html:img page="/images/l1.gif" width="8" height="8"/></td>

<td height="8" background="<%=request.getContextPath()%>/images/t_bg.gif"><html:img page="/images/transparent.gif" width="8" height="8"/></td>

<td width="8" height="8"><html:img page="/images/r1.gif" width="8" height="8"/></td>

</tr>

<tr>

<td width="8" background="<%=request.getContextPath()%>/images/l_bg.gif"><html:img page="/images/transparent.gif" width="8" height="8"/></td>

<td>

<table width="100%" border="1" cellpadding="0" cellspacing="0" bgcolor="c3cad0" bordercolordark="#c3cad0" bordercolorlight="#526472" class="List-Table">

<tbody>

<tr>

<td bgcolor="c3cad0" colspan="7" class="DetailDescription-TdCN">

</td>

</tr>

<tr bgcolor="c3cad0">

<font color="red">你对这个教师的总体评价是:</font> 

<logic:iterate id="elect" name="Elects">

<html:radio property="genRadioValue" value="value" idName="elect"/>

<bean:write name="elect" property="label"/>

</logic:iterate>

</tr>

<tr>

<td align="center" class="ListDescription-TdCN"><p>编号</p></td>

<td align="center" class="ListDescription-TdCN"><p>考评项</p></td>

<td align="center" class="ListDescription-TdCN"><p>听课评价</p></td>

</tr>

<logic:iterate id="AssessForm01" name="AssessList">

<tr>

<td align="center" class="ListValue-TdCN">

<bean:write name="AssessForm01" property="assessId"/> 

</td>

<td align="center" class="ListValue-TdCN"><bean:write name="AssessForm01" property="acontent"/> </td>

<td align="center" class="ListValue-TdCN">

<%

k=id[i++];

//temp="value(assess"+k+")";

out.print("assess"+k);

// String name="value(el"+i+")";

%>

<html:radio property='<%="value(assess"+k+")"%>' value="SUP"/>优 

<html:radio property='<%="value(assess"+k+")" %>' value="GOOD"/>良好 

<html:radio property='<%= "value(assess"+k+")" %>' value="GENERAL"/>一般 

<html:radio property='<%= "value(assess"+k+")"%>' value="DIFF"/>差 

<html:radio property='<%= "value(assess"+k+")"%>' value="VERYBAD"/>很差 

</td>

</tr>

</logic:iterate>

<tr align="center" bgcolor="#c3cad0">

<td></td> 

<td align="right">

<input type="submit" class="Standard-ButtonCN" value="<bean:message key="label.ok"/>" onclick="return submitScore();">  

<html:reset>重 置</html:reset>  

</td>

<td align="left">

<input type="submit" class="Standard-ButtonCN" value="<bean:message key="label.back"/>" onclick="return back();">  

</td>

</tr>

</table>

</td>

<td width="8" background="<%=request.getContextPath()%>/images/r_bg.gif"><html:img page="/images/transparent.gif" width="8" height="13"/></td>

</tr>

<div>

<tbody>

<tr>

<td height="8"><html:img page="/images/l2.gif" width="8" height="8"/></td>

<td height="8" background="<%=request.getContextPath()%>/images/b_bg.gif"><html:img page="/images/transparent.gif" width="8" height="8"/></td>

<td width="8" height="8"><html:img page="/images/r2.gif" width="8" height="8"/></td>

</tr>

</tbody>

</div>

</table>

</logic:present>

<logic:notPresent name="AssessList" scope="request">

<table width="100%">

<tr align="center">

<td align="center">

<h3><bean:message key="label.NoData"/></h3>

</td>

</tr>

</table>

</logic:notPresent>

</td>

</html:form>

<!--

-->

<!--foot begin-->

<center>

<tr>

<div align="center">

<%@ include file="../include/header.jsp"%>

</div>

</tr>

</center>

</table>

</body>

</html:html>

wuliugenghutin
2006-03-30 19:09
不好意思没发好

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@ taglib uri="struts-bean" prefix="bean" %>
<%@ taglib uri="struts-html" prefix="html" %>
<%@ taglib uri="struts-logic" prefix="logic" %>
<%@ taglib uri="teach" prefix="teach"%>
<%@ page import="com.teachmanage.util.javabeans.MyUtility" %>
<%@ page import="java.util.*" %>
<%
String contextPath = request.getContextPath();
String confirmMsg = MyUtility.getMessage("label.delete.Confirm");
   ArrayList assesslist=(ArrayList)session.getAttribute("AssessNoList");
 int leng=assesslist.size();
 String assesno[]=new String[leng];
 int id[]=new int[leng];
 for(int j=0;j<leng;j++){
    assesno[j]=(String)assesslist.get(j);
    id[j]=Integer.parseInt(assesno[j]);
 }
 int i=0;
  //String temp="";
 int k=0;
 out.print(leng);
%>
<html:html>
<HEAD>
<TITLE>
<bean:message key="Teach.title"/>
<html:base/>
</TITLE>
<script language="javaScript">
function back(){
  document.form2.strutsAction.value="0";
  document.form2.action="/teachmanager/person/assess.do";
  document.form2.submit();
  }
function submitScore(){    
     alert("dd");
    document.form2.strutsAction.value="4";   
    document.form2.submit();
  }

</script>
<META content="text/html; charset=utf-8" http-equiv=Content-Type><LINK
href="<%=contextPath%>/css/pub.css" rel=stylesheet type=TEXT/CSS>
<META content="MSHTML 5.00.3819.300" name=GENERATOR>
</HEAD>

<body leftMargin=0 topMargin=0 MARGINheight="0" MARGINwidth="0">
<teach:menu/>
<table>
<tr  >
<td vAlign=top>
<%@ include file="../side.jsp"%>
</td>

<html:form name="form2" action="/student/assesslist" type="com.teachmanage.assess.javabeans.AssessForm">
<html:hidden property="strutsAction"/>
<html:hidden property="teachName"/>
<html:hidden property="pagerOffSet"/>

<TD vAlign="top" align="left" width=100%>
<TABLE border=0 cellPadding=0 cellSpacing=0 width=90% align="center">
  <TR>
    <TD><B><FONT color=#835CA2>学生考评管理</FONT></B><IMG border=0
      src="<%=contextPath%>/images/arrow.gif">
    </TD>
    <TD align=right><A
                  href="javascript:this.location.reload();">刷新</A>
    </TD>
  </TR>
  <TR bgColor=#000000>
    <TD colSpan=2><IMG alt="" border=0 height=1
      src="<%=contextPath%>/images/dot(1).gif" width=1>
    </TD>
  </TR>
</TABLE>
<br>
<br>

<br>
<logic:present name="AssessList">
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0" class="Detail-Table-Bigest">
  <tr>
    <td width="8" height="8"><html:img page="/images/l1.gif" width="8" height="8"/></td>
    <td height="8" background="<%=request.getContextPath()%>/images/t_bg.gif"><html:img page="/images/transparent.gif" width="8" height="8"/></td>
    <td width="8" height="8"><html:img page="/images/r1.gif" width="8" height="8"/></td>
  </tr>

  <tr>
    <td width="8" background="<%=request.getContextPath()%>/images/l_bg.gif"><html:img page="/images/transparent.gif" width="8" height="8"/></td>
    <td>
      <table width="100%" border="1" cellpadding="0" cellspacing="0" bgcolor="c3cad0" bordercolordark="#c3cad0" bordercolorlight="#526472" class="List-Table">
        <tbody>  
        <tr>
            <td bgcolor="c3cad0" colspan="7" class="DetailDescription-TdCN">
             
            </td>	    
          </tr>
	   <tr bgcolor="c3cad0">	
	   <font color="red">你对这个教师的总体评价是:</font>&nbsp;	    
	    <logic:iterate id="elect" name="Elects">
	          <html:radio property="genRadioValue" value="value" idName="elect"/>
		   <bean:write name="elect" property="label"/>
	     </logic:iterate>
	   </tr>
          <tr>
            <td align="center" class="ListDescription-TdCN"><p>编号</p></td>
            <td align="center" class="ListDescription-TdCN"><p>考评项</p></td>	   
            <td align="center" class="ListDescription-TdCN"><p>听课评价</p></td>          
          </tr>
          <logic:iterate id="AssessForm01"  name="AssessList">       
	  <tr>
            <td align="center" class="ListValue-TdCN">		
                <bean:write name="AssessForm01" property="assessId"/>&nbsp;
            </td>
            <td align="center" class="ListValue-TdCN"><bean:write name="AssessForm01" property="acontent"/>&nbsp;</td>          
            <td align="center" class="ListValue-TdCN">
	    <%
	         k=id[i++];	
		 //temp="value(assess"+k+")";
	        out.print("assess"+k);
	      // String name="value(el"+i+")";
	    %>
	       <html:radio property='<%="value(assess"+k+")"%>' value="SUP"/>优&nbsp;
	       <html:radio property='<%="value(assess"+k+")" %>' value="GOOD"/>良好&nbsp;
	       <html:radio property='<%= "value(assess"+k+")" %>' value="GENERAL"/>一般&nbsp;
	       <html:radio property='<%= "value(assess"+k+")"%>' value="DIFF"/>差&nbsp;
	       <html:radio property='<%= "value(assess"+k+")"%>' value="VERYBAD"/>很差&nbsp;	  
	       
	    </td>
          </tr>
	   
        </logic:iterate>
	 <tr align="center" bgcolor="#c3cad0">	
	 <td></td>&nbsp;
	     <td align="right">
	     <input type="submit" class="Standard-ButtonCN" value="<bean:message key="label.ok"/>" onclick="return submitScore();">&nbsp;&nbsp;
	     <html:reset>重 置</html:reset>&nbsp;&nbsp;	   
	   </td>
	   <td align="left">
	    <input type="submit" class="Standard-ButtonCN" value="<bean:message key="label.back"/>" onclick="return back();">&nbsp;&nbsp;
	   </td>
	     </tr>
      </table>
    </td>
    <td width="8" background="<%=request.getContextPath()%>/images/r_bg.gif"><html:img page="/images/transparent.gif" width="8" height="13"/></td>
  </tr>
  <div>
   <tbody>
  <tr>
    <td height="8"><html:img page="/images/l2.gif" width="8" height="8"/></td>
    <td height="8" background="<%=request.getContextPath()%>/images/b_bg.gif"><html:img page="/images/transparent.gif" width="8" height="8"/></td>
    <td width="8" height="8"><html:img page="/images/r2.gif" width="8" height="8"/></td>
  </tr>
  </tbody>
  </div>
</table>
</logic:present>
<logic:notPresent name="AssessList" scope="request">
 <table width="100%">
  <tr align="center">
    <td align="center">
	  <h3><bean:message key="label.NoData"/></h3>
	</td>
</tr>	
</table>
</logic:notPresent>
</td>
</html:form>
<!--

-->
<!--foot begin-->
<center>
<tr>
<div align="center">
  <%@ include file="../include/header.jsp"%>
</div>
</tr>
</center>
</table>
</body>
</html:html>
<p>

wuliugenghutin
2006-03-30 19:10
formbean和action代码

package com.teachmanage.assess.javabeans;

import com.teachmanage.util.javabeans.BaseModel;
import com.teachmanage.util.javabeans.MyDebug;
import java.util.*;
import javax.servlet.http.*;
import org.apache.struts.action.ActionMapping;
/**
 * Created by IntelliJ IDEA.
 * User: wuliugeng
 * Date: 2005-12-5
 * Time: 21:46:49
 * To change this template use File | Settings | File Templates.
 */
public class AssessModel extends BaseModel{
    private final Map map=new HashMap();	
    int size=getSize();
    private String assessId;    //考评项编号&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;
    private String acontent;    //考评项内容&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;
    private String proportion;  //考评项权重&#65533;&#65533;&#65533;&#65533;
    private String genRadioValue="SUP";//对应AssessList表单中的第一组<html:radio>
    private List values=new ArrayList();
    private ArrayList assessRadioValue;//存贮AssessList表单中某学生对某教师的所有考评项的值&#65533;
    //private String radioValue[]=new String[size];
    private String radioName;
    private String teachNo;
    private String teachName;
    private String courName;
    private ArrayList assessScore;//存贮某学生对某教师的各处考评项的分数
    private String deleteAssessId;
    
    public AssessModel(){
    
    }
    public void clear(){
        assessId="";
        acontent="";
        proportion="";
	genRadioValue="SUP";
	for(int i=0;i<size;i++){
	  String key=Integer.toString(i);
	  String temp="SUP";
	  map.put(key,temp);	
	  values.set(i,temp);
	}
	 radioName="";
	assessRadioValue=null;
	teachNo="";
	teachName="";
	courName="";
        assessScore=null;
        deleteAssessId="";
    }
    public void setValue(String key,Object value){
	MyDebug.println("map.pub("+key+","+value+")");    
	map.put(key,value);   
	MyDebug.println("get: "+map.get(key));
	MyDebug.println("map size: "+map.size());
    }
    public Object getValue(String key){
	 MyDebug.println("asdfds "+map.get(key));   
	 MyDebug.println("key: "+key);
	 return map.get(key);   
    }
    public Map getMap(){
	return this.map;    
    }
    public void setRadioName(String string){
	 this.radioName=string;    
    }
    public String getRadioName(){
	return this.radioName;    
    }
     public void setCourName(String string){
      this.courName=string;
    }
    public String getCourName(){
	return this.courName;    
    }
     public void setAssessScore(ArrayList score){
	this.assessScore=score;    
    }
    public ArrayList getAssessScore(){
    return this.assessScore;
    }
  /* public void setValue(int key,Object value){
        values.set(key,value);
    }
    public Object getValue(int key){
	    MyDebug.println("ass "+values.get(key));
	return values.get(key);    
    }*/
    public void setAssessId(String string){
        this.assessId = string;
    }
    public String getAssessId(){
        return this.assessId;
    }
    public void setAcontent(String string){
        this.acontent = string;
    }
    public String getAcontent(){
        return this.acontent;
    }
    public void setProportion(String string){
        this.proportion = string;
    }
    public String getProportion(){
        return this.proportion;
    }
    public void setDeleteAssessId(String string){
        this.deleteAssessId=string;
    }
    public String getDeleteAssessId(){
        return this.deleteAssessId;
    }
    public void setTeachNo(String string){
      this.teachNo=string;
    }
    public String getTeachNo(){
	return this.teachNo;    
    }
    public void setTeachName(String string){
      this.teachName=string;
    }
    public String getTeachName(){
	return this.teachName;    
    }
     public void setGenRadioValue(String string){
	    this.genRadioValue=string;	 
     }
     public String getGenRadioValue(){
	   return this.genRadioValue;	 
     }
     public void setAssessRadioValue(ArrayList radiovalue){
	    this.assessRadioValue=radiovalue;	 
     }
     public ArrayList getAssessRadioValue(){
	   return this.assessRadioValue;
    }
    public void reset(ActionMapping mapping,HttpServletRequest request){
	values.clear();   
	map.clear();
    }
    public static int getSize(){
	    int size=0;
	    try{
	       AssessProxy aproxy=new AssessProxy();
               ArrayList ssess=aproxy.getAssessNo();
	       size=ssess.size();
	    }catch(Exception e){
		e.printStackTrace();    
	    }
	    return size;
    }
}

private ActionForward performStudentAssess(ActionMapping mapping, ActionForm actionform,
                                              HttpServletRequest request, HttpServletResponse response) {
        ActionForward forward=null;
        AssessForm form=(AssessForm)actionform;
	MyDebug.println("you assess teacher is: "+form.getTeachName()); 
	ArrayList elects=new ArrayList();
	elects.add(new LabelValueBean("优","SUP"));
	elects.add(new LabelValueBean("良好","GOOD"));
	elects.add(new LabelValueBean("一般","GENERAL"));
	elects.add(new LabelValueBean("差","DIFF"));
	elects.add(new LabelValueBean("很差","VERYBAD"));
        MyDebug.println("action is: "+form.getStrutsAction());
	MyDebug.println("genRadioValue is: "+form.getGenRadioValue());
	MyDebug.println("map size: "+form.getMap().size());
        try {
             ArrayList assessno=proxy.getAssessNo();
             String assess[]=new String[assessno.size()];
	    // AssessModel amodel=form.getModel();
            if(form.getStrutsAction()==0){
	       MyPagers pager=form.getPager();
		//ArrayList assessno=proxy.getAssessNo();
                ArrayList assesslist=proxy.Query(form.getModel());
                MyDebug.println("Total Assess Record: "+assesslist.size());
                if(assesslist==null || assesslist.size()==0){
                    MyDebug.println("Assess Record is null");
                    request.setAttribute(MyContants.Error_Name,MyUtility.getMessage("label.NoData"));
                }else{
                    request.getSession().setAttribute("AssessNoList",assessno); 
		    request.getSession().setAttribute("Elects",elects);
                    request.getSession().setAttribute("AssessList",assesslist);
                    request.setAttribute(MyContants.Pager_Session,pager);
                     MyDebug.println("setAttribute complete");
                }
		
            }else{
                 int id[]=new int[assessno.size()];
	       ArrayList selscore=new ArrayList();	
	       for(int j=0;j<assessno.size();j++){
                 // assess[j]=(String)assessno.get(j);
		 String temp=(String)assessno.get(j);
                  //int key=Integer.parseInt(assess[j]);
	         String assid="assess"+temp;
		 
		 // String assid=Integer.toString(j);
		  MyDebug.println("assess: "+assid);
	          String e=(String)form.getValue(assid);
		  MyDebug.println("assessvalue: "+e);
	          selscore.add(e);
                }    
		MyDebug.println("begin caculate");
		MyDebug.println("selscore size: "+selscore.size());
		CaCulateProxy ccproxy=new CaCulateProxy();
		String stdno=(String)request.getSession().getAttribute("userId");
		TeacherProxy tproxy=new TeacherProxy();
		TeacherModel tmodel=tproxy.QueryByTeacherName(form.getTeachName());
		if(selscore==null||selscore.size()==0){
			MyDebug.println("selscore is null");
			return forward=mapping.findForward("success");
		}else{
		float genass=ccproxy.GeneralAss(selscore);
		ccproxy.CaScore(ccproxy.SelCorseTran(selscore),genass,tmodel.getTeachNo(),stdno);
		form.setGenRadioValue(ccproxy.ApprisRank(selscore));
                form.reset(mapping,request);   
		}
            }
        } catch (Exception e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
             request.setAttribute(MyContants.Error_Name,MyUtility.getMessage("Teach.Assess.Error.SearchAssessError"));
        }
      
        forward=mapping.findForward("success");
        MyDebug.println("complete");
        return forward;  //To change body of created methods use File | Settings | File Templates.
    }

wuliugenghutin
2006-03-30 19:12
控制台错误信息

map.pub(assess3,DIFF)

get: DIFF

map size: 1

map.pub(assess6,DIFF)

get: DIFF

map size: 2

map.pub(assess8,DIFF)

get: DIFF

map size: 3

map.pub(assess9,DIFF)

get: DIFF

map size: 4

map.pub(assess12,DIFF)

get: DIFF

map size: 5

map.pub(assess10,DIFF)

get: DIFF

map size: 6

map.pub(assess4,DIFF)

get: DIFF

map size: 7

map.pub(assess1,DIFF)

get: DIFF

map size: 8

map.pub(assess11,DIFF)

get: DIFF

map size: 9

map.pub(assess7,DIFF)

get: DIFF

map size: 10

map.pub(assess2,DIFF)

get: DIFF

map size: 11

AssessAction:studentassess

you assess teacher is:

action is: 4

genRadioValue is: SUP

map size: 0

select AssessId from Assess

assess: assess1

asdfds null

key: assess1

assessvalue: null

assess: assess2

asdfds null

key: assess2

assessvalue: null

assess: assess3

asdfds null

key: assess3

assessvalue: null

assess: assess4

asdfds null

key: assess4

assessvalue: null

assess: assess6

asdfds null

key: assess6

assessvalue: null

assess: assess7

asdfds null

key: assess7

assessvalue: null

assess: assess8

asdfds null

key: assess8

assessvalue: null

assess: assess9

asdfds null

key: assess9

assessvalue: null

assess: assess10

asdfds null

key: assess10

assessvalue: null

assess: assess11

asdfds null

key: assess11

assessvalue: null

assess: assess12

asdfds null

key: assess12

assessvalue: null

begin caculate

selscore size: 11

select TeachNo,TeachName,Sex,BirthDay,CollegeNo,TzMm,GraduatCollege,Degree,Title,Introduces from Teachers where TeachName=''

size: 11

sel size: 11null

猜你喜欢