为何选中2号机,点确定按钮页面提交后,
机组选项仍为1号机,各位大侠给点建议,能否不用javascript函数解决问题,多谢
<%@ page language="java" contentType="text/html; charset=gb2312"pageEncoding="gb2312"%>
<%@ page import = "java.util.Date" %>
<% Date date=new Date();
int currentY = date.getYear()+1900;
int currentM = date.getMonth()+1;
int currentD = date.getDate();
        String[][] names= { {"1号机","1001"},{"2号机","1002"}};
        int unitNum=names.length;        String sYear=request.getParameter("year");
        String sMonth=request.getParameter("month");
        String sDay=request.getParameter("day");
        String sUnitId=request.getParameter("bidunit_id");
       
        if (sYear==null) {
            sYear=String.valueOf(currentY);
        } 
        if (sMonth==null) {
            sMonth=String.valueOf(currentM);
        }
        if (sDay==null) {
            sDay=String.valueOf(currentD);
        }        if (sUnitId==null) {
            System.out.println("sUnitId null......................");
            sUnitId=names[0][1];  //第一次默认取第一个机组id
        }
        String sDate=sYear+"-"+sMonth+"-"+sDay;
        int year = Integer.parseInt(sYear);
        int month =Integer.parseInt(sMonth);
        int day=Integer.parseInt(sDay);
     
%><body >
<form id="d_gen_form" method="post">
            <div>
<table width="100%" border=0>
<tr>
<td style="font-size:14px" colspan=2 height="5" align="right"></td>
</tr>
<tr>
<td style="font-size:14px" align="right" width=70%>
                时间:
        <select id="year" name="year" style="HEIGHT: 20px; WIDTH:60px">
<%
  for (int i=currentY - 5;i<=currentY + 3;i++) {
%>
                            <option
<%     
if (i == year) { 
%>
                 selected
<% 
  } 
%>
                >    <%=i%>
                </option>
<%
}
%>                
                </select>年
                <select id="month" name="month" style="HEIGHT: 20px; WIDTH:60px">
<%
  for (int j = 1 ; j <= 12; j++) {
%>           
                        <option
<%
  if (j == month) {
%>
selected 
<% 
  } 
%>
><%=j%>
</option>
<%
}
%>
</select>月
<select id="day" name="day" style="HEIGHT: 20px; WIDTH:60px"><%
  for (int k = 1 ; k <= 31; k++) {
%>           
                        <option
<%
  if (k == day) {
%>
selected 
<% 
  } 
%>
><%=k%>
</option>
<%
}
%>
</select>日
</td>
            <td style="font-size:14px" align="right" width=20%;> 
                   机组:
                <select id="bidunit" name="bidunit" style="HEIGHT: 20px;" >
<% 
  for (int l=0;l<unitNum;l++)  {

  if (sUnitId == names[l][1]) {
%>
<option selected value="<%=names[l][1]%>">
              <%=names[l][0]%>
        </option>
<% 
  } else {
%>
<option value=="<%=names[l][1]%>">
               <%=names[l][0]%>
        </option>
<%
}  }
%>
      </select>
              </td>
  <td  width=8% align="right">
   <input type="button"  value="确定"  onClick="submit()">
      </td>
</tr>
<tr>
<td style="font-size:13px" colspan=2 align="left">
单位:兆瓦
</td>
</tr>
<tr>
<td style="font-size:14px" colspan=2 height="5"></td>
</tr>
</table>
        </div>
</form>
</body>

解决方案 »

  1.   

    应该是你的数据没有传输好!你可以debug一下,看看页面中传过来的sUnitId 正确与否,在来判断。
      

  2.   

    关键现在问题是一提交,就进入如下:
            if (sUnitId==null) { 
                System.out.println("sUnitId null......................"); 
                sUnitId=names[0][1];  //第一次默认取第一个机组id 
            } 
    如何处理啊,大侠帮忙,好久不搞技术了,JSP忘了
      

  3.   

    String sUnitId=request.getParameter("bidunit_id"); <select id="bidunit" name="bidunit" style="HEIGHT: 20px;"  >名字错了
      

  4.   

    <%  
      for (int l=0;l <unitNum;l++)  {   if (sUnitId == names[l][1]) {   ==>sUnitId.equals(names[l][1]);
    % > 
    <option selected value=" <%=names[l][1]% >" > 
                   <%=names[l][0]% > 
             </option > 
    <%  
      } else { 
    % > 
    <option value==" <%=names[l][1]% >" > 
                    <%=names[l][0]% > 
             </option > 
    <% 
    }  } 
    % > 谢谢楼上的,还有如上用红色的问题
    自己太粗心了
      

  5.   

    <%  
      for (int l=0;l <unitNum;l++)  {   if (sUnitId == names[l][1]) {   ==>sUnitId.equals(names[l][1]);
    % > 
    <option selected value=" <%=names[l][1]% >" > 
                   <%=names[l][0]% > 
             </option > 
    <%  
      } else { 
    % > 
    <option value==" <%=names[l][1]% >" > 
                    <%=names[l][0]% > 
             </option > 
    <% 
    }  } 
    % > 谢谢楼上的,还有如上用红色的问题,问题已经解决了。
    自己太粗心了
      

  6.   

      <%
        String ordertype=func.format(request.getParameter("ordertype"));
    if (ordertype.equals("error")||ordertype==null){
      ordertype="";
    }

    %> <form name="form2" method="post" action="">
            <tr bgcolor="#FFFFFF">
              <td width="217" height="25" align="right">部门类别:</td>
              <td height="25" colspan="3">
      <SELECT name="ordertype" size="1" onchange="javascript:form.submit()" dataType="Require" msg="请选择部门类别">
                <OPTION selected value="">-=请选择=-</OPTION>
                <%
    String sqlt="select * from depttype order by deptnum asc";
    rs=st.executeQuery(sqlt);
    while(rs.next())
    {%>
                <OPTION value="<%=rs.getString("id")%>"><%=rs.getString("deptname")%></OPTION>
                <%}%>
              </SELECT>
        <script>
    <%if(ordertype!=null){%>
    document.all("ordertype").value="<%=ordertype%>";
    <%}%>
    </script>
    </td>
              </tr>
    </form>
    ////////////////////////////////从我程序中直接摘取的,没有怎么改动,应该能看懂吧!!!!