aspose file tools*
The moose likes JSP and the fly likes Show menu and submenu on homepage from database using servlet and jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Show menu and submenu on homepage from database using servlet and jsp" Watch "Show menu and submenu on homepage from database using servlet and jsp" New topic
Author

Show menu and submenu on homepage from database using servlet and jsp

shilpa deshmukh-kadam
Ranch Hand

Joined: Jun 01, 2012
Posts: 38
Hi All,
I want subcategory dropdown menu on my home page.I am using jsp and servlet.database is mysql. tables are as below
1.tbl_category(category_id(pk),category_name)
2.tbl_subcategory(subcategory_id(pk),category_id(fk),subcategory_name)
There is a servlet for fetch record. code is as below


This can fetch records and display with the help of jsp




output is as below
Home Sports Kitchen Furniture

The problem is that It shows only menus ont the submenu what can I do for that?
Thank you in adv.
Palak Mathur
Ranch Hand

Joined: Jan 29, 2007
Posts: 313

Why do you think it would show submenu? Where are you trying to display that? The code is showing what you are doing in the code. If you want to display the submenu, try to implement that part.


Palak Mathur | My Blog | TechJaunt | What is JavaRanch? | List of All FAQs
shilpa deshmukh-kadam
Ranch Hand

Joined: Jun 01, 2012
Posts: 38
Palak Mathur wrote:Why do you think it would show submenu? Where are you trying to display that? The code is showing what you are doing in the code. If you want to display the submenu, try to implement that part.

Actually sir,
This is working code which shows output as

Home Sports Kitchen Furniture
Which are store in my table data but the output which I want is dropdown submenus over above menu for that I tried following code too

Servlet code


and jsp code is as below



and css code is ---------



Now no error is shown it shows output 80% how I want that means it shows categories as mentioned above, subcategories on mouse over but in case of subcategory It shows subcategory of category id='3' where I want each related subcategory of related parent category.
I know the mistake in my query but don't know which query I have to fired...?

Palak Mathur
Ranch Hand

Joined: Jan 29, 2007
Posts: 313

Check following line of your doGet() method:-



So here you are fetching the subcategory_name from table tbl_subcategory for the category_id = 3 only. In place of this you should pass the category id corresponding to each category.
shilpa deshmukh-kadam
Ranch Hand

Joined: Jun 01, 2012
Posts: 38


This is code which display subcategory_name of category id 3. but I have different-different categories and those having more subcategories so is there any option like as loop to get subcategory_name . I mean to say as category_id=i;
i++;
just asking if I expected funny Then please guide me.

If It's wrong So..
Do I write different jsp for each category_id ...?
Palak Mathur
Ranch Hand

Joined: Jan 29, 2007
Posts: 313

Why will you use a loop? I think you will like to use a join while querying. Fetch the category_id from tbl_category and use it to fetch data from tbl_subcategory.

Your query would look like this (you will have to modify to optimize this query following the rules of using a join):

shilpa deshmukh-kadam
Ranch Hand

Joined: Jun 01, 2012
Posts: 38
I tried that like as below


The show.jsp contains following code


Which shows following output

•Sports
◦Table Tennis
•Sports
◦Pool Cues
•Sports
◦Foot-Ball
•Exercise and Fitness
◦Yoga
•Exercise and Fitness
◦Bars

and so on....here categories too repeated which I don't want.

help me..?
Palak Mathur
Ranch Hand

Joined: Jan 29, 2007
Posts: 313

When you are adding to the list, what you are doing is you are adding category_name as it comes in the RS. Do not add category name and subcategory name to the same list. I would suggest that you use a Map with category name as the key and list of subcategoryname as value. Display the key and corresponding subcategory list.
shilpa deshmukh-kadam
Ranch Hand

Joined: Jun 01, 2012
Posts: 38
can you give me example...?
I don't know about how to use map...
Even I didn't know about Iterator class while doing code I search on google and make various code snippet. Iterator, Array are the examples which gives me output .
So would you give me an example or give me just syntax I will try..Please suggest me reference book for this topic.
Thank you
Palak Mathur
Ranch Hand

Joined: Jan 29, 2007
Posts: 313

shilpa deshmukh-kadam wrote:can you give me example...?
I don't know about how to use map...
Even I didn't know about Iterator class while doing code I search on google and make various code snippet. Iterator, Array are the examples which gives me output .
So would you give me an example or give me just syntax I will try..Please suggest me reference book for this topic.
Thank you


Refer this tutorial: http://docs.oracle.com/javase/tutorial/collections/interfaces/map.html
shilpa deshmukh-kadam
Ranch Hand

Joined: Jun 01, 2012
Posts: 38
Thank you :)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Show menu and submenu on homepage from database using servlet and jsp