Greetings,

I'm slowly building up code to do the following:-

  1. Display TWO selection option boxes (cascading).
  2. If the FIRST selection option box changes then reload the jsp using onchange event (not changing the option box value on relaod i.e. not re-running the SQL query).
  3. ONLY on initial entry should the form FIRST selection option box should be populated using JDBC SQL.
  4. The SECOND selection option box can then be populated from the value of the FIRST selection option box.
  5. Then when the selection is made from the SECOND selection option box display the correspong record details

My code was attempting to check the value of the option box and if it was null i.e. the first time the user had entered the screen then populate the Option value ELSE just forward its current Value which could be picked up by the SECOND selection box.

However I dont know how to check the Option value as I get the following error message due to me reloading the jsp I cant use getparameter:-

Originally Posted by
An error occurred at line: 12 in the jsp file: /examples/wk465682UserMenu.jsp
Generated servlet error:
The method getparameter(String) is undefined for the type HttpServletRequest

An error occurred at line: 12 in the jsp file: /examples/wk465682UserMenu.jsp
Generated servlet error:
OptionCategoryValue cannot be resolved

<!-- the % tag below is what is called a scriptlet tag - allows java to be embedded in the jsp -->
<%@ page import="java.util.*" %>
<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<HTML>
<H1>FAQ</H1>
<% String  OptionCategory = null;%>
<H3>Please choose a category</H3>
 
<FORM ACTION="wk465682UserMenu.jsp" METHOD="POST">
<SELECT NAME="category" onChange="location.href='wk465682UserMenu.jsp?option='+this.  value;">
        <% 
                
            Connection conn = null, conn1 = null, conn2 = null;
            
            if (request.getparameter("OptionCategoryValue") == null)    
            {                     
                try 
                    {
                        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
                        conn1 = DriverManager.getConnection("jdbc:odbc:FAQ"); 
                    }
                        catch (Exception e1)  {System.out.print(e1);}
                    {
                        try
                            {  
                                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
                                conn2 = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver*.mdb)};DBQ=C:/ProgramFiles/Apache Software Foundation/Tomcat 6.0/webapps/2008-sem2/wk465682/FAQ.mdb");        
                            }
                                catch (Exception e2) {System.out.print(e2);}
                    }
                                        
        if(conn1 == null) conn = conn2;
        else conn = conn1;
                
        PreparedStatement mystatement = conn.prepareStatement("SELECT category from category");
        ResultSet result = mystatement.executeQuery();
        
        while(result.next()) { 
                                OptionCategoryValue=result.getString(1); %>
                                <OPTION VALUE=OptionCategoryValue><%out.println(OptionCategory);%></OPTION>
                            <%}
        } %>
        
    </SELECT>
</FORM>
</HTML>
if (request.getparameter("OptionCategoryValue") == null)

should be getParameter

Now I get error message :-

An error occurred at line: 12 in the jsp file: /examples/wk465682UserMenu.jsp
Generated servlet error:
OptionCategoryValue cannot be resolved

Can any assist or offer advice, is it clear what I want to achieve?

Thanks for the reply,

I've fixed the errors, but when the user changes the value and the onChange event is actioned how do I get it to keep its previous selection?

I thought it would pass in the OptionCategory value.

Recap of working code:-

<!-- the % tag below is what is called a scriptlet tag - allows java to be embedded in the jsp -->
<%@ page import="java.util.*" %>
<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<HTML>
<H1>FAQ</H1>
<% String  OptionCategory = null;%>
<H3>Please choose a category</H3>

<FORM ACTION="wk465682UserMenu.jsp" METHOD="POST">
<SELECT NAME="category" onChange="location.href='wk465682UserMenu.jsp?option='+this.value;">
		<% 
				
			Connection conn = null, conn1 = null, conn2 = null;
			
			if (request.getParameter("OptionCategoryValue") == null) 	
			{							
				try 
					{
						Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
						conn1 = DriverManager.getConnection("jdbc:odbc:FAQ"); 
					}
						catch (Exception e1)  {System.out.print(e1);}
					{
						try
							{  
								Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
								conn2 = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver*.mdb)};DBQ=C:/ProgramFiles/Apache Software Foundation/Tomcat 6.0/webapps/2008-sem2/wk465682/FAQ.mdb");        
							}
								catch (Exception e2) {System.out.print(e2);}
					}
										
		if(conn1 == null) conn = conn2;
		else conn = conn1;
				
		PreparedStatement mystatement = conn.prepareStatement("SELECT category from category");
		ResultSet result = mystatement.executeQuery();
		
		while(result.next()) { 
								String OptionCategoryValue=result.getString(1); %>
								<OPTION VALUE="OptionCategoryValue"><%out.println(OptionCategoryValue);%></OPTION>
							<%}
		} %>
		
	</SELECT>
</FORM>
</HTML>
This question has already been answered. Start a new discussion instead.