Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 5258 | Replies: 8
![]() |
•
•
Join Date: Jan 2006
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
Hi there,
I have a problem in my controller.jsp This page aims to retrieve the device's status from my database to display on the form. After that it will update device's new status when my customer wish to change the status.
So I declared a String array status [] to get new status from user and update to my database. but... it seem like my String array does not work, it can't get the device's new status.
[code]
<%
// retrive from database
String query = "SELECT * FROM device where locationID='"+5+"' order by device_name";
dbselect.rs = dbselect.executeQuery(query);
int i=0;
while ( (dbselect.rs).next() ) {
String device = dbselect.rs.getString("device_name");
String status = dbselect.rs.getString("status");
String deviceID = dbselect.rs.getString("deviceID");
String check1 = "";
String check2 = "";
if(status.equalsIgnoreCase("ON")){
check1="checked";
}
if(status.equalsIgnoreCase("OFF")){
check2="checked";
}
%>
<tr><TD>
<%= device %>
<input type="hidden" name="device<%= i%>" value="<%=device%>">
</TD>
<TD align="center">
<input type="hidden" name="ID<%= i%>" value="<%= deviceID%>">
<input type="hidden" name="status<%= i%>" value="<%= status%>">
<input type="radio" name="button<%= i%>" value="ON" <%=check1%> >0n
<input type="radio" name="button<%=i%>" value="OFF" <%=check2%> >Off
</TD>
</TR>
<%
i++ ;
} // end while loop
%>
</table></td>
<td><img src="Image/bathroom1.JPG"></td>
</tr>
</table>
<br>
<center>
<input type="submit" name="ChangeStatus" value="Save Change">
<input type="Reset" name="Reset" value="Don't Save">
</center>
</form>
</div>
<%
//update to database
String change= request.getParameter("ChangeStatus");
String [] status = new String[i];
if (change!=null) {
for (int n=0; n<i; n++)
{
status[n] = (String)request.getParameter("button") + n;
if (status[n]!=null) {
dbselect.executeUpdate = "UPDATE device SET status = '"+status[n]+"' WHERE locationID='"+5+"' and deviceID='"+deviceID+"'";
}
}
%>
</body>
[code]
Please help me. I need it urgently. Many thankx :rolleyes:
I have a problem in my controller.jsp This page aims to retrieve the device's status from my database to display on the form. After that it will update device's new status when my customer wish to change the status.
So I declared a String array status [] to get new status from user and update to my database. but... it seem like my String array does not work, it can't get the device's new status.
[code]
<%
// retrive from database
String query = "SELECT * FROM device where locationID='"+5+"' order by device_name";
dbselect.rs = dbselect.executeQuery(query);
int i=0;
while ( (dbselect.rs).next() ) {
String device = dbselect.rs.getString("device_name");
String status = dbselect.rs.getString("status");
String deviceID = dbselect.rs.getString("deviceID");
String check1 = "";
String check2 = "";
if(status.equalsIgnoreCase("ON")){
check1="checked";
}
if(status.equalsIgnoreCase("OFF")){
check2="checked";
}
%>
<tr><TD>
<%= device %>
<input type="hidden" name="device<%= i%>" value="<%=device%>">
</TD>
<TD align="center">
<input type="hidden" name="ID<%= i%>" value="<%= deviceID%>">
<input type="hidden" name="status<%= i%>" value="<%= status%>">
<input type="radio" name="button<%= i%>" value="ON" <%=check1%> >0n
<input type="radio" name="button<%=i%>" value="OFF" <%=check2%> >Off
</TD>
</TR>
<%
i++ ;
} // end while loop
%>
</table></td>
<td><img src="Image/bathroom1.JPG"></td>
</tr>
</table>
<br>
<center>
<input type="submit" name="ChangeStatus" value="Save Change">
<input type="Reset" name="Reset" value="Don't Save">
</center>
</form>
</div>
<%
//update to database
String change= request.getParameter("ChangeStatus");
String [] status = new String[i];
if (change!=null) {
for (int n=0; n<i; n++)
{
status[n] = (String)request.getParameter("button") + n;
if (status[n]!=null) {
dbselect.executeUpdate = "UPDATE device SET status = '"+status[n]+"' WHERE locationID='"+5+"' and deviceID='"+deviceID+"'";
}
}
%>
</body>
[code]
Please help me. I need it urgently. Many thankx :rolleyes:
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,749
Reputation:
Rep Power: 19
Solved Threads: 200
think about what you're doing there.
Each time the page is loaded you first get the data from the database and then write it back. That can't be what you're trying to do.
Then you're intending to write back what the user put into the webform, but you're never retrieving those parameters.
You're retrieving only one and that one doesn't even exist on the form so will always yield an empty string.
Each time the page is loaded you first get the data from the database and then write it back. That can't be what you're trying to do.
Then you're intending to write back what the user put into the webform, but you're never retrieving those parameters.
You're retrieving only one and that one doesn't even exist on the form so will always yield an empty string.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
•
•
Join Date: Jan 2006
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
Hi jwenting,
Although the way you saying is not very friendly but I am thank you that at least you give me some suggestion.
1st, I DID retrieve my database and display on the webform successfully.
2nd, what I need to retrieve is only the status which is display on the radio button (ON or OFF). According to my database, there are quite a number of devices, so I need an array to store all the status. And I did declare it on my controller.jsp page.
3rd my String status tried to retrieve input by user through the form. This command was written inside a while loop.
for (int n=0; n<i; n++)
{
status[n] = (String)request.getParameter("button") + n;
}
I know there's something wrong with my codes but I can't figure out so I here I am asking for help. If you are pleased to help me, please read my post carefully before you raise your voice.
Kind regard,
yup
Although the way you saying is not very friendly but I am thank you that at least you give me some suggestion.
1st, I DID retrieve my database and display on the webform successfully.
2nd, what I need to retrieve is only the status which is display on the radio button (ON or OFF). According to my database, there are quite a number of devices, so I need an array to store all the status. And I did declare it on my controller.jsp page.
String [] status = new String(i);
3rd my String status tried to retrieve input by user through the form. This command was written inside a while loop.
for (int n=0; n<i; n++)
{
status[n] = (String)request.getParameter("button") + n;
}
I know there's something wrong with my codes but I can't figure out so I here I am asking for help. If you are pleased to help me, please read my post carefully before you raise your voice.
Kind regard,
yup
•
•
Join Date: Jan 2006
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
thanks ekstee,
Please take a look at these codes. Here you go!
Kind regard,
yup
Please take a look at these codes. Here you go!
<form action="Bedroom1.jsp" method="post">
<TABLE BORDER="1" width ="400" cellspacing="0" cellpadding = "2" align ="center" bgcolor="#006600">
<tr>
<td>
<TABLE BORDER="1" width ="150" cellspacing="0" cellpadding = "2" align ="center" bgcolor="#009900">
<TR><TH colspan="2" bgcolor="#99FF66" bordercolor="#009900"><span class="style5">Hanny's room</span></TH>
</tr>
<tr><TH align="center"><strong>Device</strong></TH>
<tH align="center">Status</tH></tr>
<%
String query = "SELECT * FROM device where locationID='"+1+"' order by device_name";
dbselect.rs = dbselect.executeQuery(query);
int i=0;
while ( (dbselect.rs).next() ) {
String device = dbselect.rs.getString("device_name");
String status = dbselect.rs.getString("status");
String check1 = "";
String check2 = "";
if(status.equalsIgnoreCase("ON")){
check1="checked";
}
if(status.equalsIgnoreCase("OFF")){
check2="checked";
}
%>
<tr><TD>
<%= device %>
<input type="hidden" name="device<%= i%>" value="<%=device%>">
</TD>
<TD align="center">
<input type="hidden" name="status<%= i%>" value="<%= status%>">
<input type="radio" name="button<%= i%>" value="ON" <%=check1%> >0n
<input type="radio" name="button<%=i%>" value="OFF" <%=check2%> >Off
</TD>
</TR>
<%
i++ ;
} // end while loop
%>
</table></td>
<td><img src="Image/hanny.JPG"</td>
</tr>
</table>
<br>
<center>
<input type="submit" name="ChangeStatus" value="Save Change">
<input type="Reset" name="Reset" value="Don't Save">
</center>
</form>Kind regard,
yup
•
•
Join Date: Jan 2006
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
I am using these codes and have this error message:
<%
String change= request.getParameter("ChangeStatus");
String [] status = new String[i];
if (change!=null)
{
for(int n=0; n<=i; n++) {
status[n] =request.getParameter("button") +n;
if (status[n]!= null)
out.println(status[n]);
}
}
%>
Error message:
An error occurred on page Bedroom1.jsp
The exception was:
java.lang.ArrayIndexOutOfBoundsException: 2
<%
String change= request.getParameter("ChangeStatus");
String [] status = new String[i];
if (change!=null)
{
for(int n=0; n<=i; n++) {
status[n] =request.getParameter("button") +n;
if (status[n]!= null)
out.println(status[n]);
}
}
%>
Error message:
An error occurred on page Bedroom1.jsp
The exception was:
java.lang.ArrayIndexOutOfBoundsException: 2
•
•
Join Date: Jan 2006
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
wait, i think your contoller page contains the data retrieval from the database while the bedroom1.jsp is the updating of the database. right? i'll read the code again.
<%
//update to database
String change= request.getParameter("ChangeStatus");
String [] status = new String[i];
if (change!=null) {
for (int n=0; n<i; n++)
{
status[n] = (String)request.getParameter("button") + n;
if (status[n]!=null) {
dbselect.executeUpdate = "UPDATE device SET status = '"+status[n]+"' WHERE locationID='"+5+"' and deviceID='"+deviceID+"'";
}
}
%>
is the code above supposed to be at the bedroom1.jsp
<%
//update to database
String change= request.getParameter("ChangeStatus");
String [] status = new String[i];
if (change!=null) {
for (int n=0; n<i; n++)
{
status[n] = (String)request.getParameter("button") + n;
if (status[n]!=null) {
dbselect.executeUpdate = "UPDATE device SET status = '"+status[n]+"' WHERE locationID='"+5+"' and deviceID='"+deviceID+"'";
}
}
%>
is the code above supposed to be at the bedroom1.jsp
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode