File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Problem in selection option in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem in selection option in JSP" Watch "Problem in selection option in JSP" New topic
Author

Problem in selection option in JSP

Ray Law
Greenhorn

Joined: Mar 30, 2005
Posts: 14
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

Joined: Jan 10, 2002
Posts: 60792
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ray Law
Greenhorn

Joined: Mar 30, 2005
Posts: 14
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

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ray Law
Greenhorn

Joined: Mar 30, 2005
Posts: 14
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

Joined: Feb 10, 2005
Posts: 85
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

Joined: Mar 30, 2005
Posts: 14
Thank for your advice. Can you suggest some popular java/jsp debuggers ?
 
 
subject: Problem in selection option in JSP
 
Similar Threads
Combo box problem in jsp
Problem in inserting data into access database through jsp file
jsp: forward page problem
I M NOT ABLE TO DEFINE VARIABLES IN JSP.
Returning a result set in an html form