aspose file tools*
The moose likes JSP and the fly likes Filtering Result Sets based on selectable links (a href:) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Filtering Result Sets based on selectable links (a href:)" Watch "Filtering Result Sets based on selectable links (a href:)" New topic
Author

Filtering Result Sets based on selectable links (a href:)

Ron Ingram
Ranch Hand

Joined: Mar 11, 2011
Posts: 63
Hello Forum,

Working on a class project... I have an include (header jsp) and a main view with a full result set. There are five category links added in the header jsp that when selected, the resultset in the main view should filter based on what's selected. However, I do not know how to drive a different filter or resultSet based on clicking an html link.

I can create 5 seperate action servlets for each seperate link and re-display the results, but I do not think that is the best approach.

Can someone help me with the best solution?

Here is the code:
The Include with Links:


Here is the main view with the ResultSet displayed that should filter based on the category selected



Servlet Code:


Helper Class (DAO):

Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30929
    
158

Did you know you can pass parameters in a URL. For example:
/MyServlet?category=1 or /MyServlet?category=feeding

Then in your servlet, you can filter by that category. Either with a PreparedStatement (JDBC) or an API on ProductDB that takes a where clause or even looping through the list afterwards if the first two can't be used.

Also, in the JSP< take a look at JSTL/EL. Scriptlets are an old fashioned way of putting Java code in JSPs and has fallen out of use. Since all you are doing is looping through a list, JSTLs for loop is perfect.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Ron Ingram
Ranch Hand

Joined: Mar 11, 2011
Posts: 63
Thank you, works!

Anyway to hide the parameter in the url header when clicked? I try to disguise all if possible.

I need to learn JSTL for this class, just having a hard time getting there. I appreciate your time.
Ron
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

Ron Ingram wrote:Anyway to hide the parameter in the url header when clicked? I try to disguise all if possible.

Why? That's completely counter to how HTTP and the Web are supposed to work.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ron Ingram
Ranch Hand

Joined: Mar 11, 2011
Posts: 63
Well, I don't want to allow anyone to navigate throughout a webapp by changing or messing around with the url. Would like to constrain them to navigate through the application only if possible. Also, I believe there is some security concerns by changing the url. I'm still a newbie though....
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

With all due respect, that is a bit of a newbie attitude. URLs are the heart of the web. The way to secure a web site is to make sure that no matter what the URL is that nothing can be comprised, not to try and mess around with the URL.

And aside from ensuring that no sensitive data appears unencrypted in a URL (or anywhere on the client), no real security is afforded by trying to obfuscate URLs.
Ron Ingram
Ranch Hand

Joined: Mar 11, 2011
Posts: 63
Bear, thats fine. I will adopt that approach, thanks again!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

The trend is definitely towards what has become known as "friendly" or "RESTful" URLs. Another way of putting it is that the trend is towards semantic URLs -- the exact opposite of obfuscated URLs.

This is the way that the inventors of HTTP intended it be used in the first place, but the Web just sort of lost its way somewhere along the way. Now the trend is to find its way back.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Filtering Result Sets based on selectable links (a href:)