我的应用程序中有两个radiobuttons,一个是带有组合框的meterid,另一个是带有文本框的消费者名称。现在问题是每当我选择单选按钮时,结果只是正确但我无法找到我选择的单选按钮。
My application includes the following code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.sql.*"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%
Connection con;
String sqlQuery="";
Statement st;
ResultSet rs=null;
%>
<html>
<head>
<title>Meter Search
</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="styles.css" type="text/css" media="screen" />
<link rel="stylesheet" type="text/css" href="style.css" />
<style>
td{FONT: 13px Arial,sans-serif;}
th{FONT:bold 13px Arial,sans-serif;color:white;background-color:#153e7e}
input{FONT: 13px Arial,sans-serif;border: solid 1;}
select{font: 13px Arial,sans-serif}
#button{cursor:hand}
A:hover {COLOR: red}</style>
</head>
<body onload ="noback();" onpageshow="if (event.persisted) noBack();" onunload="">
<br><br>
<form action="./metersearchsuper.jsp" method="post" name="search">
<table align="left" width="40%" border="0" cellpadding="5" cellspacing="1" bgcolor="#f8f8ff" bordercolor="#333366" >
<tbody><tr>
<th colspan="6" width ="40%" >Search options</th></tr>
<tr><td width="15%" class="options0" id="tdSearchBy" colspan="5">
<input name="r1" value="MeterID" onclick="searchOptions(0)" type="radio"><font size="4">Meter ID</font></td>
<%
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/suwatermeter","root","sumith");
sqlQuery="select distinct Meterid from Meter_List";
st=con.createStatement();
rs=st.executeQuery(sqlQuery);
%>
<td width="20%" class="options0" colspan="5"><select style="WIDTH: 150px" selected="true" name="meterid" id="meter_id" onChange="this.form.submit()">
<option>Select Meter ID</option>
<% while(rs.next()) {%>
<option value="<%=rs.getInt("MeterID")%>"><%=rs.getInt("MeterID")%></option>
<% }
rs.close();
st.close();
con.close();
%>
</select>
</td></tr>
<tr><td class="options1" id="tdSearchBy" colspan="5">
<input name="r1" value="ConsumerName" onclick="searchOptions(1)" type="radio"><font size="3">Consumer Name</font>
</td>
<td><input name="cnsearch" style="WIDTH: 150px"></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr><td style="height: 50px; border: 1px solid rgb(255, 255, 255);" colspan="4" align="center">
<input name="bSearch" value="Search" style="width: 80px; HEIGHT: 34px; border: 1px solid rgb(13, 31, 78);" onclick="return checkInput()" type="submit">
</td></tr>
</tbody></table>
<%
try{
String meterid =request.getParameter("meterid");
String cnsearch=request.getParameter("cnsearch");
String r1=request.getParameter("r1");
String flag="";
int mid;
String ConsumerName;
int SNo=1;
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/suwatermeter","root","sumith");
st=con.createStatement();
%>
<input type="hidden" id="Hmeter_id" value="<%=meterid%>">
<%
if(r1.equals("MeterID"))
{
rs=st.executeQuery("select * from Meter_List where Meterid="+meterid);
flag="false";
}
if(r1.equals("ConsumerName"))
{
rs=st.executeQuery("select * from Meter_List where Consumername='"+cnsearch+"'");
flag="false";
}
if(flag.equals("false"))
{%><br><br><br>
<table width="100%" height="20%">
<tr><td> </td></tr><tr><td> </td></tr>
<%
boolean mycolor=true;
int tHeading=0; //0 means false
if(meterid != null && cnsearch != null )
tHeading=0;
//else if(getZoneName !=null || !getZoneName.equals("") || !getZoneName.isEmpty())
// {
//tHeading=1;
// }
while(rs.next()){
String checkdate="";
SimpleDateFormat df=new SimpleDateFormat("dd-MM-yy");
checkdate=df.format(rs.getDate("Date"));
if(tHeading==0)
{%>
<table border="0" style="" width="100%" align="center" cellpadding="5" cellspacing="0">
<tbody>
<th>S No</th>
<th>Meter ID</th>
<th>Consumer ID</th>
<th>Consumer Name</th>
<th>Reading</th>
<th>Date</th>
<th>Time</th>
<th>Status</th>
<th>Sub Zone</th>
<th>Zone</th>
<%tHeading=1;
}
if(mycolor==true)
{%>
<tr>
<td align="center" bgcolor="#ffffff"><%=SNo%></td>
<td align="center" bgcolor="#ffffff"><a href="meteridinfosuper.jsp?mid=<%=rs.getInt("meterid")%>
&Consumerid=<%=rs.getInt("Consumerid")%>&Consumername=<%=rs.getString("Consumername")%>&Subzone=<%=rs.getString("Subzone")%>&Zone=<%=rs.getString("Zone")%>">
<%=rs.getInt("Meterid")%></a></td>
<td align="center" bgcolor="#ffffff"><%=rs.getInt("Consumerid")%></td>
<td align="center" bgcolor="#ffffff"><%=rs.getString("Consumername")%></td>
<td align="center" bgcolor="#ffffff"><%=rs.getInt("LastReading")%></td>
<td align="center" bgcolor="#ffffff"><%=checkdate%></td>
<td align="center" bgcolor="#ffffff"><%=rs.getTime("Time")%></td>
<td align="center" bgcolor="#ffffff"><%=rs.getString("Status")%></td>
<td align="center" bgcolor="#ffffff"><%=rs.getString("Subzone")%></td>
<td align="center" bgcolor="#ffffff"><%=rs.getString("zone")%></td>
</tr><%
mycolor=false;
}
else
{%> <!--ceefff-->
<tr>
<td align="center" bgcolor="#ceefff"><%=SNo%></td>
<td align="center" bgcolor="#ceefff"><a href="meteridinfosuper.jsp?mid=<%=rs.getInt("meterid")%>
&Consumerid=<%=rs.getInt("Consumerid")%>&Consumername=<%=rs.getString("Consumername")%>&Subzone=<%=rs.getString("Subzone")%>&Zone=<%=rs.getString("Zone")%>">
<%=rs.getInt("Meterid")%></a></td>
<td align="center" bgcolor="#ceefff"><%=rs.getInt("Consumerid")%></td>
<td align="center" bgcolor="#ceefff"><%=rs.getString("Consumername")%></td>
<td align="center" bgcolor="#ceefff"><%=rs.getInt("LastReading")%></td>
<td align="center" bgcolor="#ceefff"><%=checkdate%></td>
<td align="center" bgcolor="#ceefff"><%=rs.getTime("Time")%></td>
<td align="center" bgcolor="#ceefff"><%=rs.getString("Status")%></td>
<td align="center" bgcolor="#ceefff"><%=rs.getString("Subzone")%></td>
<td align="center" bgcolor="#ceefff"><%=rs.getString("zone")%></td>
</tr><%
mycolor=true;
}
SNo++;
}
}
rs.close();
st.close();
con.close();
}
catch(Exception e){}
%>
<script>
document.getElementById("meter_id").value=document.getElementById("Hmeter_id").value;
</script>
</table>
</body>
</html>
请帮我解决这个问题。
答案 0 :(得分:0)
通常,您只需阅读r1
中的metersearchsuper.jsp
值MeterID
或ConsumerName
作为结果。
String selected = request.getAttribute("r1");