Win a copy of Murach's Java Programming this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Accessing subcategories with the help of categories in java using jstl  RSS feed

 
Rax Sico
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am using java, mysql and glassfish server 4.0

I have two tables in my database

1.category with id and name as its fields 2.subcategory with id and name and category_id which refers to id of category table.

I am fetching all categories on first page and I am trying to access the subcategories related to category on the next page. Here are the code.

 
Tim Moores
Saloon Keeper
Posts: 3755
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What, specifically, is missing or not working in this code? Tell us what you tried, and what the result was.
 
Rax Sico
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to access subcategories when I click the category. I want that the subcategories specific to the category which i click get listed on the next page.I am giving the first page code below.

Everything is working fine but the subcategories are not displaying on the next page.

This is first page code. This page is working fine.


 
Dave Tolls
Ranch Hand
Posts: 2721
30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


If this check is false then you won't get anything appearing.
Have you checked the values you are comparing here?
Have you tried to display the data without this check?
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you tell what the SQL being generated is?

From a guess I would think it is:


Which probably won't match any actual category ids in your database.
Now why might that be happening?
 
Dave Tolls
Ranch Hand
Posts: 2721
30
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And this is one good reason not to be doing this sort of thing in a JSP page.
The SQL tags really weren't designed for anything other than quick and dirty data provision for demos.

The database access ought to be in some for of data service class(es) that you can write and then test by themselves.
Then a Servlet can provide those service(s) the data from the front end, and get the result and pass that (pre-checked_ data to the JSP.

This allows you to test this stuff far more easily, as well as debug them when you hit an issue.
Debugging a JSP page is painful.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66041
140
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:And this is one good reason not to be doing this sort of thing in a JSP page.

This is too important not to repeat, so I'll repeat it. A few times.

Dave Tolls wrote:
And this is one good reason not to be doing this sort of thing in a JSP page.
And this is one good reason not to be doing this sort of thing in a JSP page.
And this is one good reason not to be doing this sort of thing in a JSP page.
And this is one good reason not to be doing this sort of thing in a JSP page.
And this is one good reason not to be doing this sort of thing in a JSP page.

Rule of thumb: make the JSPs as dumb as possible. Make the JSPs as simple as possible. Make the JSPs do the absolute minimum to generate the HTML.

Remember, JSPs are supposed to be templates for the HTML, not units of processing.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!