• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

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

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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):

 
author & internet detective
Posts: 41988
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67750
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

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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67750
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
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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear, thats fine. I will adopt that approach, thanks again!
 
Bear Bibeault
Sheriff
Posts: 67750
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
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.
 
It's a tiny ad. At least, that's what she said.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic