Click here to Skip to main content
15,889,822 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi..

Can anyone pls help me to write a code for the dynamic menu generation from oracle or any database in jsp???
Posted
Comments
Shubhashish_Mandal 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.

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[^]
 
Share this answer
 
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.
 
Share this answer
 
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..
 
Share this answer
 
Comments
Sudhakar Shinde 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.
Replace this line:
ResultSet rs2 = st1.executeQuery(query2); 
with this line: 
ResultSet rs2 = st2.executeQuery(query2);
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900