Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can any JSP Gurus help me please!!!!

Status
Not open for further replies.

peader2001

Programmer
Jul 17, 2000
1
IE
Hello Gurus,<br><br>I am having major problems with this piece of code below.<br><br>I am using JSWDK-1.0.1&nbsp;&nbsp;and my problem is I am trying to get the selected operating system in the combo box to do a query and print the result but I don't have any idea how to do it.&nbsp;&nbsp;I am a just a beginner with java but I really need this to work.<br><br>Below is the code for the query1.jsp if anyone could please help me I would be very grateful.<br><br>The combo box populates its list from a MS Access database table with for example:<br><br>WIN 95 <br>WIN 98<br>UNIX&nbsp;&nbsp;&nbsp;etc..&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br><br><br><br><br>&lt;HTML&gt;<br>&lt;body&gt;<br><br>&lt;Form method=&quot;post&quot; action=&quot;query1.jsp&quot;&gt;&nbsp;&nbsp;<br>&lt;p&gt;&lt;b&gt;Operating System&lt;/b&gt; <br>&nbsp;&nbsp;&lt;select name=&quot;select4&quot; &gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;option selected&gt;Not Selected&lt;/option&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;option value=OperatingSystem&gt; &lt;%Class.forName(&quot;sun.jdbc.odbc.JdbcOdbcDriver&quot;);%&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;%java.sql.Connection conn = java.sql.DriverManager.getConnection(&quot;jdbc:eek:dbc:JSPQuery&quot;);%&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;%java.sql.Statement st = conn.createStatement();%&gt; &lt;%java.sql.ResultSet rs;%&gt;&lt;%st = conn.createStatement();%&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;% rs= st.executeQuery(&quot;Select Distinct OperatingSystem From OperatingSystemTable&quot;);%&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;%while (rs.next()) { %&gt; &lt;%String OperatingSystem = rs.getString(&quot;OperatingSystem&quot;);%&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;%if (OperatingSystem != null){ %&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;option value=&lt;%=OperatingSystem%&gt;&gt;&lt;%=OperatingSystem%&gt; &lt;%} %&gt; &lt;%}%&gt; <br>&nbsp;&nbsp;&lt;/select&gt;<br>&lt;p&gt;&nbsp;&lt;input type=&quot;reset&quot; name=&quot;Reset&quot; value=&quot;Reset Query&quot;&gt;<br>&lt;/form&gt; <br><br>&lt;Form method=&quot;get&quot; action=&quot;query1.jsp&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;%out.println (&quot;Selected&quot;);<br>%&gt;<br>&lt;input type=&quot;submit&quot; name=&quot;Submit&quot;<br>value=&quot;Submit Query&quot;&gt;<br>&lt;/Form&gt;<br><br>&lt;/body&gt;<br>&lt;/HTML&gt;<br><br><br><br>Thank you for your time,<br><br>Peter Daly<br><A HREF="mailto:pdaly@elandtech.com">Pdaly@elandtech.com</A><br>Ireland - Dublin
 
Hello,<br><br>I tried running your page exactly as is except for changing &quot;JSPQuery&quot; to &quot;Sunflower&quot; (a database on my computer) and I changed the column names to ones in my database.<br><br>It works fine here. I get the drop down list with all the values from my database and the submit and reset buttons under that.<br><br>I would check and see if your database is mapped correctly and make sure you have JSWDK installed correctly. I'm using JavaWebServer2.0 so I don't know what JSWDK ins and outs are.<br><br>Other than that, the script itself seems fine. <p>--Will Duty<br><a href=mailto:wduty@radicalfringe.com>wduty@radicalfringe.com</a><br><a href= > </a><br>
 
Hello again,<br><br>Actually, I think I misunderstood your question. You are asking how to proceed from this page to a page which lists a query based on the selection from the list?<br><br>If that's the question then you can do it either of two ways:<br><br>1. You can have a page called query2.jsp. You would change the form action of query1.jsp to point to that page. Then in query2.jsp you would get the selected parameter from the list in the previous page using the getParameterValues() method. Then using that parameter value you would construct another query:<br><br>query2.jsp:<br>-----------------------------<br>&lt;HTML&gt;<br>&lt;body&gt;<br>&lt;% String[] testing = null; %&gt; <br>&lt;% testing = request.getParameterValues(&quot;select4&quot;); %&gt;<br>&lt;% String temp = testing[0]; //out.print(temp); %&gt;<br>&lt;% Class.forName(&quot;sun.jdbc.odbc.JdbcOdbcDriver&quot;);%&gt; <br>&lt;% java.sql.Connection conn = java.sql.DriverManager.getConnection(&quot;jdbc:eek:dbc:Sunflower&quot;);%&gt; <br>&lt;% java.sql.Statement st = conn.createStatement();%&gt; &lt;%java.sql.ResultSet rs;%&gt;&lt;%st = conn.createStatement();%&gt; <br>&lt;% rs= st.executeQuery(&quot;SELECT * FROM products WHERE product='&quot;+temp+&quot;'&quot;);%&gt; <br>&lt;% while(rs.next()) out.print(rs.getString(&quot;description&quot;)+&quot;&lt;br&gt;&quot;); %&gt;<br>&lt;% rs.close(); %&gt;<br>&lt;/body&gt;<br>&lt;/HTML&gt;<br><br>(I just tried this on my computer and it works.)<br><br><br>2. The other way would be to have both queries in the same page but separated them with an if statement where if there's no parameter let's call it &quot;action&quot; sent to the page then the page displays the selection list. If there is a parameter called action and it's value is &quot;getresults&quot; or whatever, then do the results query.<br><br>Also you might want to consider moving all this functionality into a bean or something under the surface so you can reuse is without all this in-page code.<br><br>I hope this is closer to what you were asking. <p>--Will Duty<br><a href=mailto:wduty@radicalfringe.com>wduty@radicalfringe.com</a><br><a href= > </a><br>
 
hi there<br>There is another simple method for building combo boxes<br><br>just write about the connections and query to select but before u start writing while loop u should write,<br>...<br><br>out.println (&quot;&lt;select name=s1&gt;&quot;);<br>while (rs.next()) {<br><br>out.println (&quot;&lt;option&gt;&quot;+ rs.getString(&quot;name&quot;) + &quot;&lt;/option&gt; &quot;);<br><br>.....<br><br><br>in above code &quot;name&quot; is assumed field in a database , this is a simple method if u could try, may be this would solve ur problem lot easier <br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top