Forums

This topic is locked

Plz help me in JSP tutorial

Posted 22 Nov 2005 06:15:55
1
has voted
22 Nov 2005 06:15:55 Ngoc Lam posted:
Hi, can anyone help me in this JSP tutorial. I want to retrieve data from my database and put <b>into the option button</b>. In this tutorial, I need to retrived the status of the light from database. If the status is On ==&gt; check the On button. If status is 'OFF' ==&gt; checked the Off button.

<pre id=code><font face=courier size=2 id=code>&lt;%@ page import="java.sql.*" %&gt;

&lt;jsp:useBean id="dbselect" class="database.dbSelect" scope="session"/&gt;
&lt;jsp:useBean id="cart" scope="session" class="database.ShoppingCart" /&gt;
&lt;!-- Add an HTML table to format the results --&gt;&lt;style type="text/css"&gt;
&lt;!--
body {
background-color: #000000;
}
body,td,th {
color: #FFFFFF;
}
.style2 {color: #CCCCCC}
.style3 {color: #FF00FF}
.style4 {
color: #66CCFF;
font-weight: bold;
}
--&gt;
&lt;/style&gt;
Welcome, &lt;br&gt;
&lt;center&gt;
&lt;h1 class="style3"&gt;Home Controller&lt;/h1&gt;&lt;br&gt;
Today is &lt;%= new java.util.Date()%&gt;
&lt;/center&gt;


&lt;frame&gt;
&lt;TABLE BORDER="1" width ="400" cellspacing="0" cellpadding = "2" align ="center"&gt;
&lt;TR&gt;
&lt;TH&gt;Location&lt;/TH&gt;
&lt;TH&gt;Device&lt;/TH&gt;
&lt;TH&gt;Status&lt;/TH&gt;

&lt;/TR&gt;

&lt;%

String query = "SELECT * FROM Controller";
dbselect.rs = dbselect.executeQuery(query);
while ( (dbselect.rs).next() ) {
String device = dbselect.rs.getString("Device";
String location= dbselect.rs.getString("Location";
String status = dbselect.rs.getString("Status";
%&gt;

&lt;TR&gt;&lt;form action="MyController.jsp" method="post"&gt;
&lt;TD&gt;&lt;%= location %&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;%= device %&gt; &lt;/TD&gt;
&lt;TD&gt; &lt;input type="hidden" name="status" value= "&lt;%= status %&gt;" &gt;
&lt;input type="radio" name="button1" value="ON" &gt;ON &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&lt;input type="radio" name="button2" value="OFF"&gt;OFF&lt;/TD&gt;
&lt;/form&gt;
&lt;/TR&gt;
&lt;%
}
%&gt;
&lt;/TABLE&gt;
&lt;p&gt;
&lt;center&gt;&lt;input type="submit" name="ChangeStatus" value="Save Change"&gt; &nbsp;&nbsp;&nbsp;&lt;input type="Reset" name="Reset" value="Don't Save"&gt; &lt;/center&gt;&lt;/p&gt;
&lt;/frame&gt;
&lt;br&gt;

&lt;hr color=#a0cfeb&gt;
&lt;br&gt;
&lt;center&gt;
&lt;span class="style2"&gt;Copyright &lt;/span&gt;&lt;span class="style4"&gt; &lt;/span&gt; 2005
&lt;/center&gt;
</font id=code></pre id=code>

Reply to this topic