This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in selection option in JSP

 
Ray Law
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I try to add a selection option to select sorting sequence of retrieved records. Some JSP statements are shown :
:
<table border="0">
<tr>
<td bgcolor="#D5D5D5">Sorted by :
<select name="opt_sort" >
<option value="Asc ">Ascending</option>
<option value="Desc">Descending</option>
</select>
String sort_by = opt_sort.value;
</td>
</tr>
</table>

<table border="1">
<tr>
<td><b>Mark:</b></td>
<td><b>Name:</b></td>
<td><b>Description:</b></td>
</tr>
<% bb.connect();
if (sort_by.equals("Asc")) {
String qry_smt = "SELECT * FROM Bookmarks";}
else {
String qry_smt = "SELECT * FROM Bookmarks ORDER BY 1 DESC";}
ResultSet rs = bb.viewBookmarks(qry_smt);
while (rs.next()) {
String url = rs.getString("URL");
%>
:
:

It didn't work and Error page prompt out. as follows :
C:\Tomcat 4.1\work\Standalone\localhost\jspad\my_bookmarks_jsp.java:115: cannot resolve symbol
symbol : variable sort_by
location: class org.apache.jsp.my_bookmarks_jsp
if (sort_by.equals("Asc")) {
^

HELP ! THANKS !
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly Ray, please enclose your posted code in UBB code tags. Few people are going to read a block of unformatted code.

Secondly, take a careful look at how and where you declared the sort_by variable.
 
Ray Law
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What means about "UBB code tags", how to amend my source. would you give me more support?
Furthermore, I only want to a selection "sorting sequence" before SQL getting data via javabean, can you show me some sample and simple JSP statements to do this purpose ? Thanks.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a "CODE" button just under the text area where you type your post in this forum. Pressing it adds a CODE and /CODE tag to the text.

If you paste your code in between those tags, the indents will be preserved.
This makes your code much easier to read and thus, more likely to be read.
 
Ray Law
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding UBB Tags :
<%-- <form action="delete.jsp" method="post"> --%>
<table border="0">
<tr>
<td bgcolor="#D5D5D5">Sorted by :
<select name="opt_sort" >
<option value="Asc ">Ascending</option>
<option value="Desc">Descending</option>
</select>
<%
String sort_by = opt_sort.value;
%>
</td>
</tr>
</table>

After running UBB,I runs it and another error message prompt out :
C:\Tomcat 4.1\work\Standalone\localhost\jspad\my_bookmarks_jsp.java:97: cannot resolve symbol
symbol : variable opt_sort
location: class org.apache.jsp.my_bookmarks_jsp
String sort_by = opt_sort.value;
^
 
Heonkoo Lee
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're getting that error when the page is compiled at first visit. The compiler is complaining about unresolved variable opt_sort, which is not a java variable in the page, but an html document form element. You seem like mixing java and javascript code in the jsp scriptlet.
(document.form.opt_sort.value : javascript code)

It will be much easier to track down bugs if you break down into separate pages assuming you are not familiar with servlets. At front end a simple html or jsp to display the html form with action url targetting another jsp page that acts as both action controller (processing request) and view component (displaying results).

Probably in the future you will not want to write any logic in JSP pages, but in servlets with helper classes. After basic understanding of servlet/JSP, you might be interested in MVC frameworks. Am I going too far?

Regards,
[ April 01, 2005: Message edited by: Heonkoo Lee ]
 
Ray Law
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank for your advice. Can you suggest some popular java/jsp debuggers ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic