• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

coding help needed

 
Ranch Hand
Posts: 399
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I am doing a small project using servlets and JSP. My database is MS SQL 2000.

COuld you any one help me giving a sample code to implement the following:

Display drop down list which takes names from database table1.
When one name in the first drop down is selected, it displays second drop down list depending on the name selected in first drop down list. When a name is selected in second drop down list a third drop down list is displayed. When element in third drop down list is selected a weblink is displayed which is obtained from the database.

What would be the database structure and also how this can be implemented using JSP, servlets, html?

Thanks in advance.
 
Ayub ali khan
Ranch Hand
Posts: 399
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry I would like to add some more information to the previous post:

It should have a text box which if any new name is entered, it is added to the first drop down list which is automatically updated in the database.
another option which can be used to delete any entry from the first drop down list if required.

Thank you
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd implement everything using JavaScript. Check http://www.backbase.com.
 
Ayub ali khan
Ranch Hand
Posts: 399
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for fast reply. I was not able to where to search for in http://www.backbase.com./ website. However I have to use a database so that new entries can be added and removed from the drop down menu.

Any ideas how to do using a database?

Thanks
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When an option is select, it fires the "onselect" event handler, you can in this event handler, post a request to the server ,and get the result back, use DOM to insert these items into the second select.
 
Ayub ali khan
Ranch Hand
Posts: 399
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks FU. Could you give me an example code to understand it better?
 
Ayub ali khan
Ranch Hand
Posts: 399
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Following is my Application directory:

Project:
WEB-INF
Classes
ApplicationServlet.class
web.xml
index.jsp

index.jsp(contains all the code to query the database and display the initial drop down menu).

Below is the code for the respective files:
==============
index.jsp
==============
<%@ page import="java.sql.*" %>

<html>
<body>

<form method="GET" action="SelectTechnology"/>

<%

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://niting:1433;databaseName=Technology","sa","sa");

Statement stmt=conn.createStatement();

ResultSet rs=stmt.executeQuery("select techname from table1");

%>

<select name="technology">
<%
while(rs.next())
{
out.print("<option>"+rs.getString("techname")+"</option>");
}

%>

</select>

<br>
<br>

<form method="GET" action="SelectTechnology">
Enter name of Technology <input type="textbox" name="t1"><br><br>
<input type="submit" value="submit">
<br> <br>
</form>

Enter name to be deleted <input type="textbox" name="t2"><br><br>
<input type="submit" value="submit">
<br> <br>


</body>
</html>

=============
ApplicationServlet.java
==================
import javax.servlet.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;

public class ApplicationServlet extends HttpServlet{

Connection conn;
public void doGet(HttpServletRequest req,HttpServletResponse res) throws

ServletException,IOException{
int flag=0;
Statement stmt;
ResultSet rs;
List li=new ArrayList();

res.setContentType("text/html");

try{

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection
conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://niting:1433;databaseName=Technology"

,"sa","sa");

stmt=conn.createStatement();

rs=stmt.executeQuery("select techname from table1");

while(rs.next())
{
li.add(rs.getString("techname"));
}

Search se=new Search();

flag=se.find(li,req.getParameter("t1").toUpperCase());

if(flag==1)
{
stmt.execute("insert into table1 (techname) values('"+req.getParameter("t1").toUpperCase()+"')");
li.add(req.getParameter("t1").toUpperCase());
req.setAttribute("technology",li);
RequestDispatcher view=req.getRequestDispatcher("index.jsp");
view.forward(req,res);
}

else
{
flag=0;
RequestDispatcher errview=req.getRequestDispatcher("errview.jsp");
errview.forward(req,res);

}

conn.close();
stmt.close();
rs.close();

}//end try

catch(Exception e){System.out.println(e);}

} //end doPost

}//end class

=================
Search.java (class used to search the database for duplicate entries
=====================
class Search{

public int find(List li,String s){
int flag=0;

Collator c=Collator.getInstance();

Iterator it=li.iterator();

while(it.hasNext())

{
if(c.compare(s,it.next())==0)

{ flag=0; }

else {flag=1; }

}

return(flag);

} //end find

} //end search

Could any one help me find a better solution with code example that I can use to implement the cascaded drop down menus which use database?
 
Ayub ali khan
Ranch Hand
Posts: 399
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any witty brians out there could solve this puzzle?

Thanks
 
Ayub ali khan
Ranch Hand
Posts: 399
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could any one help me out?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ayub,
Ease Up.

I have an example app on my site that does this.
Look for "DynamicSelectLists".

http://simple.souther.us/not-so-simple.html
 
Ayub ali khan
Ranch Hand
Posts: 399
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ben,

Thanks for a wonderful solution you have provided. My sincere apologies if I have troubled some one here. You have really made a big help to me. I am improving on my programming skills.I was stuck in a small project. I tried to search in google, however could not get what I was looking for. Your examples will surely make me little wiser now

Thanks for your Wonderful help !!!
 
I love a woman who dresses in stainless steel ... and carries tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic