here is my code with notes:
Expand|Select|Wrap|Line Numbers
- <%@ page language="java" contentType="text/html; charset=windows-1256"
- pageEncoding="windows-1256"%>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <%@ page import="java.io.IOException"%>
- <%@ page import="java.sql.Connection"%>
- <%@ page import="java.sql.DriverManager"%>
- <%@ page import="java.sql.PreparedStatement"%>
- <%@ page import="java.sql.ResultSet"%>
- <%@ page import="javax.servlet.http.*" %>
- <%@ page import="javax.servlet.http.HttpServletRequest" %>
- <%@ page import="javax.servlet.http.HttpServletResponse" %>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
- </head>
- <body>
- <%!
- private Connection connect = null;
- private PreparedStatement pstmnt;
- private String sql;
- private String sql1;
- private ResultSet rs;
- private String cc= "";
- String cat_e="";
- %>
- <div align="center"><b>Subscription Form</b></div><br/>
- <form name="subfrm" align="center" action="SaveSubscription">
- Event Category: <select name="evnt_cat">
- <option value="0">--Select Category--</option>
- <%
- try {
- connect = DriverManager.getConnection("jdbc:odbc:MyEvent","","");
- sql = "SELECT * FROM Event";
- pstmnt = connect.prepareStatement(sql);
- rs = pstmnt.executeQuery();
- while(rs.next()) {
- cat_e = rs.getString("Event_Category");
- %>
- <option value="<%=cat_e%>"><%=cat_e%></option>
- <% }
- rs.close();
- pstmnt.close();
- connect.close();
- }
- catch( Exception e ) {
- System.out.println(e);
- }
- %>
- </select><br/><br/>
- Event Sub_Category: <select name="evnt_subcat">
- <option value="0">--Select Subcategory--</option>
- <%
- try {
- connect = DriverManager.getConnection("jdbc:odbc:MyEvent","","");
- sql1 = "SELECT EventDetails.Event_Title FROM Event INNER JOIN EventDetails ON Event.Event_ID = EventDetails.Event_ID WHERE Event.Event_Category = ?";
- pstmnt = connect.prepareStatement(sql1);
- pstmnt.setString(1,"The selected value from the 1st combobox");<--- Note: here, I need to put the value selected from the first combobox.
- rs = pstmnt.executeQuery();
- while(rs.next()) {
- cc = rs.getString("Event_Title");
- %>
- <option value="<%=cc%>"><%=cc%></option>
- <% }
- rs.close();
- pstmnt.close();
- connect.close();
- }
- catch( Exception e ) {
- System.out.println(e);
- }
- %>
- </select><br/><br/>
- <input name="subusr" value="Subscribe" type="submit" align="center"/>
- </form>
- </body>
- </html>