• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem in selection option in JSP

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
^
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank for your advice. Can you suggest some popular java/jsp debuggers ?
 
reply
    Bookmark Topic Watch Topic
  • New Topic