Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Can any JSP Gurus help me please!!!!

Can any JSP Gurus help me please!!!!

Can any JSP Gurus help me please!!!!

Hello Gurus,

I am having major problems with this piece of code below.

I am using JSWDK-1.0.1  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.  I am a just a beginner with java but I really need this to work.

Below is the code for the query1.jsp if anyone could please help me I would be very grateful.

The combo box populates its list from a MS Access database table with for example:

WIN 95
WIN 98
UNIX   etc..        


<Form method="post" action="query1.jsp">  
<p><b>Operating System</b>
  <select name="select4" >
    <option selected>Not Selected</option>
    <option value=OperatingSystem> <%Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");%>
    <%java.sql.Connection conn = java.sql.DriverManager.getConnection("jdbc:odbc:JSPQuery");%>
    <%java.sql.Statement st = conn.createStatement();%> <%java.sql.ResultSet rs;%><%st = conn.createStatement();%>
    <% rs= st.executeQuery("Select Distinct OperatingSystem From OperatingSystemTable");%>
    <%while (rs.next()) { %> <%String OperatingSystem = rs.getString("OperatingSystem");%>
    <%if (OperatingSystem != null){ %>
    <option value=<%=OperatingSystem%>><%=OperatingSystem%> <%} %> <%}%>
<p> <input type="reset" name="Reset" value="Reset Query">

<Form method="get" action="query1.jsp">
     <%out.println ("Selected");
<input type="submit" name="Submit"
value="Submit Query">


Thank you for your time,

Peter Daly
Ireland - Dublin

RE: Can any JSP Gurus help me please!!!!


I tried running your page exactly as is except for changing "JSPQuery" to "Sunflower" (a database on my computer) and I changed the column names to ones in my database.

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.

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.

Other than that, the script itself seems fine.

--Will Duty

RE: Can any JSP Gurus help me please!!!!

Hello again,

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?

If that's the question then you can do it either of two ways:

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:

<% String[] testing = null; %>
<% testing = request.getParameterValues("select4"); %>
<% String temp = testing[0]; //out.print(temp); %>
<% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");%>
<% java.sql.Connection conn = java.sql.DriverManager.getConnection("jdbc:odbc:Sunflower");%>
<% java.sql.Statement st = conn.createStatement();%> <%java.sql.ResultSet rs;%><%st = conn.createStatement();%>
<% rs= st.executeQuery("SELECT * FROM products WHERE product='"+temp+"'");%>
<% while(rs.next()) out.print(rs.getString("description")+"<br>"); %>
<% rs.close(); %>

(I just tried this on my computer and it works.)

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 "action" sent to the page then the page displays the selection list. If there is a parameter called action and it's value is "getresults" or whatever, then do the results query.

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.

I hope this is closer to what you were asking.

--Will Duty

RE: Can any JSP Gurus help me please!!!!

hi there
There is another simple method for building combo boxes

just write about the connections and query to select but before u start writing while loop u should write,

out.println ("<select name=s1>");
while (rs.next()) {

out.println ("<option>"+ rs.getString("name") + "</option> ");


in above code "name" is assumed field in a database , this is a simple method if u could try, may be this would solve ur problem lot easier

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close