JSP: Cascading option box problems ...

Thread Solved

Join Date: Mar 2007
Posts: 36
Reputation: Robtyketto is an unknown quantity at this point 
Solved Threads: 0
Robtyketto Robtyketto is offline Offline
Light Poster

JSP: Cascading option box problems ...

 
0
  #1
Mar 15th, 2008
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
  1. <!-- the % tag below is what is called a scriptlet tag - allows java to be embedded in the jsp -->
  2. <%@ page import="java.util.*" %>
  3. <%@ page language="java" %>
  4. <%@ page import="java.sql.*" %>
  5. <HTML>
  6. <H1>FAQ</H1>
  7. <% String OptionCategory = null;%>
  8. <H3>Please choose a category</H3>
  9.  
  10. <FORM ACTION="wk465682UserMenu.jsp" METHOD="POST">
  11. <SELECT NAME="category" onChange="location.href='wk465682UserMenu.jsp?option='+this. value;">
  12. <%
  13.  
  14. Connection conn = null, conn1 = null, conn2 = null;
  15.  
  16. if (request.getparameter("OptionCategoryValue") == null)
  17. {
  18. try
  19. {
  20. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
  21. conn1 = DriverManager.getConnection("jdbc:odbc:FAQ");
  22. }
  23. catch (Exception e1) {System.out.print(e1);}
  24. {
  25. try
  26. {
  27. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
  28. 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");
  29. }
  30. catch (Exception e2) {System.out.print(e2);}
  31. }
  32.  
  33. if(conn1 == null) conn = conn2;
  34. else conn = conn1;
  35.  
  36. PreparedStatement mystatement = conn.prepareStatement("SELECT category from category");
  37. ResultSet result = mystatement.executeQuery();
  38.  
  39. while(result.next()) {
  40. OptionCategoryValue=result.getString(1); %>
  41. <OPTION VALUE=OptionCategoryValue><%out.println(OptionCategory);%></OPTION>
  42. <%}
  43. } %>
  44.  
  45. </SELECT>
  46. </FORM>
  47. </HTML>
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 36
Reputation: Robtyketto is an unknown quantity at this point 
Solved Threads: 0
Robtyketto Robtyketto is offline Offline
Light Poster

Re: JSP: Cascading option box problems ...

 
0
  #2
Mar 16th, 2008
  1. 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?
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: JSP: Cascading option box problems ...

 
0
  #3
Mar 16th, 2008
says it all, that variable doesn't exist...
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 36
Reputation: Robtyketto is an unknown quantity at this point 
Solved Threads: 0
Robtyketto Robtyketto is offline Offline
Light Poster

Re: JSP: Cascading option box problems ...

 
0
  #4
Mar 16th, 2008
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:-

  1. <!-- the % tag below is what is called a scriptlet tag - allows java to be embedded in the jsp -->
  2. <%@ page import="java.util.*" %>
  3. <%@ page language="java" %>
  4. <%@ page import="java.sql.*" %>
  5. <HTML>
  6. <H1>FAQ</H1>
  7. <% String OptionCategory = null;%>
  8. <H3>Please choose a category</H3>
  9.  
  10. <FORM ACTION="wk465682UserMenu.jsp" METHOD="POST">
  11. <SELECT NAME="category" onChange="location.href='wk465682UserMenu.jsp?option='+this.value;">
  12. <%
  13.  
  14. Connection conn = null, conn1 = null, conn2 = null;
  15.  
  16. if (request.getParameter("OptionCategoryValue") == null)
  17. {
  18. try
  19. {
  20. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
  21. conn1 = DriverManager.getConnection("jdbc:odbc:FAQ");
  22. }
  23. catch (Exception e1) {System.out.print(e1);}
  24. {
  25. try
  26. {
  27. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
  28. 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");
  29. }
  30. catch (Exception e2) {System.out.print(e2);}
  31. }
  32.  
  33. if(conn1 == null) conn = conn2;
  34. else conn = conn1;
  35.  
  36. PreparedStatement mystatement = conn.prepareStatement("SELECT category from category");
  37. ResultSet result = mystatement.executeQuery();
  38.  
  39. while(result.next()) {
  40. String OptionCategoryValue=result.getString(1); %>
  41. <OPTION VALUE="OptionCategoryValue"><%out.println(OptionCategoryValue);%></OPTION>
  42. <%}
  43. } %>
  44.  
  45. </SELECT>
  46. </FORM>
  47. </HTML>
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: JSP: Cascading option box problems ...

 
0
  #5
Mar 17th, 2008
pass the selected value back and set it as the "selected" attribute of the dropdown.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 36
Reputation: Robtyketto is an unknown quantity at this point 
Solved Threads: 0
Robtyketto Robtyketto is offline Offline
Light Poster

Re: JSP: Cascading option box problems ...

 
0
  #6
Mar 18th, 2008
All working now, thanks for your input
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the JSP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC