Hello Lancelot,
there are many ways of doing, especially if you wish to seperate
business logic from content.
Below is a simple way of doing everything from one JSP page (which many
authors and programmers including me dont recommend for a commercial
solution) but its a good way to learn, and get into it.
Maybe someone else would like to comment on how to change this in away
to seperate business logic and content? ;)
The JSP assumes the use of JDBC-ODBC.
<html>
<head>
<title>Untitled Document</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<FORM action=actionpage.jsp method=get name=actionpage>
<P>Select the department:
<select name="record">
<%
String dsn="xx";
String user="xx";
String password="xx";
%>
<%@ page info="database handler"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<%
ResultSet rs;
Connection con;
try {
//Load JDBC-ODBC Driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:" + dsn;
con=DriverManager.getConnection(url, user,
password);
Statement stmt = con.createStatement();
String query="SELECT department_no,
department_name FROM department";
rs = stmt.executeQuery(query);
while(rs.next()) {
out.println("<option value=" +
rs.getString("department_no") + ">" +
rs.getString("department_name")</option>");
} //end while
con.close();
} catch(Exception e) { e.printStackTrace(); }
%>
</select>
</FORM>
</body>
</html>
Goodluck, Andrew
-----Original Message-----
From: Claudio Parnenzini [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, 15 August 2001 6:15 PM
To: [EMAIL PROTECTED]
Subject: Re: I need all you help
>Who know how to implement drop-down-list in JSP? I mean that when the
>JSP was invoked the JSP code fetch data from database via JDBC and fill
the
>information(such as department name and department number) in the
>drop-down-list in JSP and after the user select one item, the
>value(department number) was sent to servlet or javabean.
Parse you resultset directly into the JSP or create a bean that generate
this dropdown list. If you would like to forward the user choice
directly, one way is to send your form using Javascript event ( onChange
).
Hope this respond to your question, if not let me know.
Regards
-----Original Message-----
From: lancelot [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, August 15, 2001 4:17 AM
To: [EMAIL PROTECTED]
Subject: I need all you help
Excuse me,
Who know how to implement drop-down-list in JSP? I mean that when
the
JSP was invoked the JSP code fetch data from database via JDBC and fill
the
information(such as department name and department number) in the
drop-down-list in JSP and after the user select one item, the
value(department number) was sent to servlet or javabean.
And it's better if another function can be implemented, that is if
you
input the department number(0006 for example) then the department name
can
be fetch out automaticly(FA Dept. for expamle).
I need all your help.
Thanks a lot.
Lancelot
==========================================================================To
unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets