Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ron Ingram
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ron Ingram
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ron Ingram
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear, thats fine. I will adopt that approach, thanks again!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic