| Author |
Filtering Result Sets based on selectable links (a href:)
|
Ron Ingram
Ranch Hand
Joined: Mar 11, 2011
Posts: 60
|
|
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
internet detective
Marshal
Joined: May 26, 2003
Posts: 26193
|
|
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: 60
|
|
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: 56207
|
|
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.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Ron Ingram
Ranch Hand
Joined: Mar 11, 2011
Posts: 60
|
|
|
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: 56207
|
|
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: 60
|
|
|
Bear, thats fine. I will adopt that approach, thanks again!
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56207
|
|
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.
|
 |
 |
|
|
subject: Filtering Result Sets based on selectable links (a href:)
|
|
|