| | |
JSP: Cascading option box problems ...
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Mar 2007
Posts: 36
Reputation:
Solved Threads: 0
Greetings,
I'm slowly building up code to do the following:-
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:-
I'm slowly building up code to do the following:-
- Display TWO selection option boxes (cascading).
- 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).
- ONLY on initial entry should the form FIRST selection option box should be populated using JDBC SQL.
- The SECOND selection option box can then be populated from the value of the FIRST selection option box.
- 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
JSP Syntax (Toggle Plain Text)
<!-- 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>
•
•
Join Date: Mar 2007
Posts: 36
Reputation:
Solved Threads: 0
JSP Syntax (Toggle Plain Text)
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
•
•
Join Date: Mar 2007
Posts: 36
Reputation:
Solved Threads: 0
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:-
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:-
JSP Syntax (Toggle Plain Text)
<!-- 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>
![]() |
Other Threads in the JSP Forum
- Previous Thread: sending email
- Next Thread: retaining spaces between characters
| Thread Tools | Search this Thread |
apache backbutton combobox connection database development directorystructure dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 network parameters passing ping printinserverinsteadofclient redirect request.getparameter response servlet servletdopost()readxml sessions software ssl state_saving_method stocks sun tomcat tutorial update video web






