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
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.
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....
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.
Joined: Mar 11, 2011
Bear, thats fine. I will adopt that approach, thanks again!