943,095 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 4763
  • JSP RSS
Mar 18th, 2010
0

display combo box value on same JSP page

Expand Post »
my question is related to JSP and HTML.
i have a jsp page which have three combo box and a button.
one combo box for a class. two combo box for from_year, to_year.
i want to reterive data on this same JSP page from database based on
combo box value.
my requirement is after select the item from combo boxes then i click
to button, table could be show the data based on criteria of combo box
value on the same Jsp page.

presently, i am checking for a one combo box.

i tried this but no suceesull:

JSP Syntax (Toggle Plain Text)
  1. <tr>
  2. <td>
  3.  
  4. <select name='class_name'>
  5. <%
  6. for(int i=1;i<12;i++)
  7. {
  8. out.println("<option value="+i+">"+i+"</option>");
  9. }
  10. %>
  11. </td>
  12. <td>
  13. <input type="submit" name="submit" value="Go" ></td>
  14. </td>
  15.  
  16. <%
  17. String submit=request.getParameter("submit");
  18. if(submit!=null && (submit.equals("Go")))
  19.  
  20. {
  21. String class_name=request.getParameter("class_name");
  22.  
  23. // database connectivity
  24.  
  25. %>
please suggest.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vij123 is offline Offline
20 posts
since Oct 2008
Mar 18th, 2010
0
Re: display combo box value on same JSP page
I think you forget to close select here,still problem exists post the full code
Reputation Points: 8
Solved Threads: 2
Newbie Poster
mohamedsafiq is offline Offline
13 posts
since Jan 2010
Mar 18th, 2010
1
Re: display combo box value on same JSP page
there is my code. please correct where is wrong.
JSP Syntax (Toggle Plain Text)
  1. <tr>
  2. <td width="60"height="30">
  3. <select name='class_name'>
  4. <%
  5. for(int i=1;i<12;i++)
  6. {
  7. out.println("<option value="+i+">"+i+"</option>");
  8. }
  9. %>
  10. </td>
  11.  
  12. <select name='from_year'>
  13. <%
  14. for(int i=2010;i>2000;i--)
  15. {
  16. out.println("<option value="+i+">"+i+"</option>");
  17. }
  18. %>
  19. </td>
  20. <td>
  21.  
  22. <select name='to_year'>
  23. <%
  24. for(int i=2010;i>2000;i--)
  25. {
  26. out.println("<option value="+i+">"+i+"</option>");
  27. }
  28. %>
  29. </td>
  30.  
  31. <td>
  32. <input type="submit" name="submit" value="Go" ></td>
  33. </tr>
  34.  
  35. <table align="center" border="1" align="center">
  36.  
  37. <br>
  38. <tr bgcolor="#36559E" align="center">
  39. <td width="150"height="30"><font size="+1">Year</td></font>
  40. <td width="150"height="30"><font size="+1">Class</td></font>
  41. <td width="150"height="30"><font size="+1">Subject</td></font>
  42. <td width="150"height="30"><font size="+1">Total Students</td></font>
  43. <td width="150"height="30"><font size="+1">Passout Students</td></font>
  44. <td width="150"height="30"><font size="+1">Marks Obtained 60 To 80</td></font>
  45. <td width="150"height="30"><font size="+1">Marks Obtained over 80</td></font>
  46. <td width="150"height="30"><font size="+1">Overall Result</td></font>
  47.  
  48. </tr>
  49.  
  50.  
  51.  
  52. <%
  53. String submit=request.getParameter("submit");
  54.  
  55. if(submit!=null && (submit.equals("Go")))
  56.  
  57. {
  58. String class_name=request.getParameter("class_name");
  59. System.out.println("class_name is"+
  60. class_name);
  61. Connection con = null;
  62. try {
  63. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
  64.  
  65.  
  66. con = DriverManager.getConnection("jdbc:odbc:sql;user=sa;password=1234");
  67. System.out.println("First connection ok.");
  68.  
  69.  
  70. System.out.println("Connection created");
  71. Statement st=con.createStatement();
  72. System.out.println("st going to execute");
  73.  
  74. String query="SELECT year, class, Subject, total_students, passout_students, marks_obtained_60_to_80, marks_obtained_above_80, overall_result FROM Result where class=' "+class_name+" ' ";
  75.  
  76. System.out.println("now data are selecting");
  77.  
  78. ResultSet rs=st.executeQuery(query);
  79. System.out.println("now data in rs.....");
  80. System.out.println("now going to rs block............");
  81. while(rs.next())
  82. {System.out.println("now in rs block............");
  83. %>
  84.  
  85. <tr align="center">
  86. <td width="150"height="30"><%out.println(rs.getString(1));%>
  87. <td width="150"height="30"><%out.println(rs.getString(2));%>
  88. <td width="150"height="30"><%out.println(rs.getString(3));%>
  89. <td width="150"height="30"><%out.println(rs.getString(4));%>
  90. <td width="150"height="30"><%out.println(rs.getString(5));%>
  91. <td width="150"height="30"><%out.println(rs.getString(6));%>
  92. <td width="150"height="30"><%out.println(rs.getString(7));%>
  93. <td width="150"height="30"><%out.println(rs.getInt(8));%>
  94. <td width="150"height="30"><%out.println(rs.getString(9));%>
  95. </tr>
  96.  
  97. <%
  98. }
  99. rs.close();
  100. con.close();
  101.  
  102. }catch(Exception e){out.println(e);}
  103.  
  104. }
  105. }
  106. %>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vij123 is offline Offline
20 posts
since Oct 2008
Mar 18th, 2010
0
Re: display combo box value on same JSP page
@vij123

1. Slap on hand for doing database connectivity directly from JSP
2. I do not think you want to learn new technology like JSF or Apache Velocity, the only option I can offer for dynamic data without previously mentioned technologies is to use asynchronous AJAX or jQuery calls to servlet to get data
Last edited by peter_budo; Mar 18th, 2010 at 12:21 pm.
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,649 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: Configuring Tomcat behind SSL enabled Apache htttp sever
Next Thread in JSP Forum Timeline: How to get free domain for jsp execution??





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC