Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java J2EE JSP struts
Hi..
 
Can anyone pls help me to write a code for the dynamic menu generation from oracle or any database in jsp???
Posted 27-Apr-13 20:50pm
Comments
Shubhashish_Mandal at 28-Apr-13 2:12am
   
Nobody help you to writing your codes, instead if you stuck. Attempt it do then if you fall let us know where is you stuck.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

It does not work like this here.
 
Here is what is expected of enquirers:
1. TRY first what you want to do! You may find that it's not that hard.
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this.

 

A similar question with few headsup to start: Dynamically populating menu items from the database in JSP or javascript[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Sometimes we need to generate menu form database according to our requirements. The following url

[^] will help you to generate menu dynamically in ASP.NET. You can apply your customize CSS as you like to give nice outlook of the menu.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

My jsp page is:
 
<![CDATA[<%@page contentType="text/html" pageEncoding="UTF-8"%>]]>
<![CDATA[<%@page language="java" import="java.util.*" %>]]>
<![CDATA[<%@page language="java" import="java.sql.*" %>]]>
 

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="skin.css">
        <title>JSP Page</title>
    </head>
    <body>
        <div>
            <%
                ArrayList list = new ArrayList();
                ArrayList sublist = new ArrayList();
                try {
                    Class.forName("oracle.jdbc.OracleDriver");  
                    Connection con = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/ORCL", "PORDFW", "PORDFW");
            %>
            <ul>
                <%
                    String query1 = "select * from tbl_category";
                    Statement st1 = con.createStatement();
                    ResultSet rs1 = st1.executeQuery(query1);
                    
                    while (rs1.next()) {
                        
 
                %>
                <li>
                    <a href="#">
 
                        <%= rs1.getString("category_name")%>
                    </a>
                    <ul>
                        <%
                            String query2 = "select subcategory_name from tbl_subcategory where category_id='" + rs1.getString("category_id") + "'";
                            Statement st2 = con.createStatement();
                            ResultSet rs2 = st1.executeQuery(query2);
                            while (rs2.next()) {
                        %>
                        <li>
                            <a href="#">
                                <%= rs2.getString("subcategory_name")%>
                            </a>
                        </li>
                        <%
                            }
                        %>
                    </ul>
                </li>
                <%
                    }
                %>
            </ul>
            <%
                } catch (Exception e1) {
                }
            %>
        </div>  
    </body>
</html>
 

 
</link>
 

my database has 2 tables:
 
1. tbl_category - > category_id, category_name
2. tbl_subcategory - > subcategory_id, category_id, subcategory_name
 
First table has 2 values as
Category_id Category_name
------------ --------------
1 Sports
2 Books
 
Second table values,
Subcategory_id Category_id Subcategory_name
-------------- ------------ -----------------
1 1 Cricket
2 1 Football
3 2 Science
4 2 Maths
 
My CSS :
ul {
font-family: Arial, Verdana;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
}
ul li {
display: block;
position: relative;
float: left;
}
li ul {
display: none;
}
ul li a {
display: block;
text-decoration: none;
color: #ffffff;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #2C5463;
margin-left: 1px;
white-space: nowrap;
}
ul li a:hover { background: #617F8A; }
li:hover ul {
display: block;
position: absolute;
}
li:hover li {
float: none;
font-size: 14px;
}
li:hover a { background: #617F8A; }
li:hover li a:hover { background: #95A9B1; }
ul li.next {
position: absolute;
display: block;
float: left;
background:#E8E8E8;
font-size: 14px;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
}
ul li a.first {
background: #617F8A;
}
 

When i run this jsp, i am getting the menu as:
 
Sports
> Cricket
> Footbal
 
I am not getting the second menu "Books" with its submenu....
 

Pls help me...
 
Thanks in advance..
  Permalink  
Comments
Sudhakar Shinde at 6-May-13 3:15am
   
You can not ask a question as a solution. You need to use 'Improve Question' link to provide these details instead of putting those as a solution.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Replace this line:
ResultSet rs2 = st1.executeQuery(query2); 
with this line: 
ResultSet rs2 = st2.executeQuery(query2);
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Marcin Kozub 310
1 OriginalGriff 248
2 Sergey Alexandrovich Kryukov 215
3 Richard MacCutchan 202
4 Praneet Nadkar 197
0 OriginalGriff 8,048
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 11 Feb 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100