Jsp entry examples - multimedia classrooms single booking
Abstract: jsp entry examples - multimedia classrooms single booking
</ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle">
This article will demonstrate how you use Apache Tomcat JSP + to create multimedia classrooms appointment alone.
1, interface requirements:
The first week alone multimedia classrooms appointment
I would like to booking <table width = "56%" border = 1> <tr> <td width="12%"> </ td> <td width="12%"> Monday </ td> <td width = "12%"> Tuesday </ td> <td width="12%"> Wednesday </ td> <td width="12%"> Thursday </ td> <td width="13%"> Friday </ td> <td width="13%"> Saturday </ td> <td width="14%"> Sunday </ td> </ tr> <tr> <td> the first quarter </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td > </ tr> <tr> <td> section </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td> <td> < / td> <td> </ td> <td> </ td> </ tr> <tr> <td> the third quarter </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td> </ tr> <tr> <td> IV </ td> < td> </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td> </ tr> <tr> <td> Section V </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td> </ tr> <tr> <td> VI </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td> </ tr> <tr> <td> Section VII </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td> </ tr> <tr> <td> VIII </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td> <td> </ td> <td > </ td> <td> </ td> </ tr> </ table>
Among them, "I would like to reserve" hyperlinks to fill booking single page.
Second, install Tomcat
Tomcat installed first, and then we set up the working directory.
First, in the c: \ Tomcat 5.0 \ webapps directory to create a subdirectory called yyd. Then yyd subdirectory,
Creating standards for Web application directory structure:
C: \ Tomcat 5.0 \ webapps \ yyd
C: \ Tomcat 5.0 \ webapps \ yyd \ WEB-INF
C: \ Tomcat 5.0 \ webapps \ yyd \ WEB-INF \ classes
C: \ Tomcat 5.0 \ webapps \ yyd \ WEB-INF \ classes \ dingdan
Third, we set up the appointment database single database for storing records of the appointment of teachers, open Access, to create the database dingdan, archiving kept in:
C: \ Tomcat 5.0 \ webapps \ yyd \ WEB-INF \ dingdan.mdb
In creating 25 Table: guestbook1, guestbook2 … guestbook25. Like the structure of each table, as follows:
Field Description </ td> <td> field </ td> <td> data types </ td> <td> whether empty </ td> </ tr> <tr> <td> # </ td > <td> serial_no </ td> <td> automatically # </ td> <td> not </ td> </ tr> <tr> <td> name </ td> <td> name </ td> < td> text </ td> <td> not </ td> </ tr> <tr> <td> several weeks </ td> <td> week </ td> <td> text </ td> <td> not </ td> </ tr> <tr> <td> first sections of </ td> <td> jie </ td> <td> text </ td> <td> not </ td> </ tr> <tr> <td> class topics </ td> <td> content </ td> <td> text </ td> <td> not </ td> </ tr> </ table>
We use 25 tables corresponding one semester of 25 weeks, so manageable. Of course, it could also be a table. Week and jie field with the text type.
Fourth, set up data sources
To win2000 example, from the control panel to open the management tools "ODBC data source management," and click "System DSN" tab, in which data sources dingdan added, pointing us in the creation of a database dingdan.mdb above.
5, multimedia classrooms appointment single file structure
Making use of this appointment will be five single document:
Dingdan.jsp choose week, the main document.
Index1.jsp appointment this week showed that the document jsp
Adddingdan.jsp fill the appointments for teachers alone
Okdingdan.jsp appointment will be recorded into the database
Dingdan.java for connecting to database
(1) Dingdan.jsp booking option is for teachers of the week, jsp documents, and is responsible for the index1.jsp transmission parameters. The original code is as follows:
<% @ Page contentType = "text / html; gb2312 charset ="%>
<body>
Multimedia classrooms appointment alone
<table Border="0" width="103%" cellspacing="0" cellpadding="0" height="1">
<tr> <form Name="guideform" action=index1.jsp target="_blank" method="post">
<select Name="guidelinks">
<option SELECTED value="1"> first week
<option Value="2"> second week
<option Value="3"> third week
<option Value="4"> fourth week
<option Value="5"> fifth week
<option Value="6"> sixth week
<option Value="7"> seventh week
<option Value="8"> 8 weeks
<option Value="9"> ninth week
<option Value="10"> 10th week
<option Value="11"> Week 11
<option Value="12"> 12 weeks
<option Value="13"> 13 weeks
<option Value="14"> 14th week
<option Value="15"> 15th week
<option Value="16"> 16th week
<option Value="17"> 17 weeks
<option Value="18"> 18th week
<option Value="19"> 19 weeks
<option Value="20"> 20th week
<option Value="21"> 21 weeks
<option Value="22"> 22 weeks
<option Value="23"> 23 weeks
<option Value="24"> 24 weeks
<option Value="25"> 25th week
</ Select> <input type = "submit" name = "go" value = "Go!"
</form>
</ Tr>
</ Table>
</ Body>
(2) to show that this week's index1.jsp booking situation
Week booking situation with an array week [] [] record, first of all, the array will be given initial:
For (int i = 0; i <= 8; i + +)
For (int j = 0; j <= 7; j + +)
Week [i] [j] = "";
Week [0] [1] = "Monday";
Week [0] [2] = "Tuesday";
Week [0] [3] = "Wednesday";
Week [0] [4] = "Thursday";
Week [0] [5] = "Friday";
Week [0] [6] = "Saturday";
Week [0] [7] = "Sunday";
For (int i = 1; i <= 8; i + +)
Week [i] [0] = "" + i + "Festival";
This array of other elements of value from the database to read out
Rs = showBean.executeQuery ( "SELECT * FROM guestbook" + sn1);
While (Rs.next ()) (
E1 = Rs.getString (the "week");
Name1 = Rs.getString ( "name");
E2 = Rs.getString ( "jie");
Int k = Integer.parseInt (e1);
Int l = Integer.parseInt (e2);
Week [l] [k] = name1;
)
Finally, a week shown in the table [] []. The original code is as follows:
<% @ Page contentType = "text / html; gb2312 charset ="%>
<head>
<script LANGUAGE="javascript">
Function newwin (url) (
Var newwin = window.open (url, "newwin", "toolbar = no, location = no, directories = no,
Status = no, menubar = no, scrollbars = yes, resizable = yes, width = 400, height = 350 ");
Newwin.focus ();
Return false;
)
</ Script>
</ Head>
<body Bgcolor="#FFFFCC">
<script LANGUAGE="javascript">
Function submit11 ()
(
Self.location.replace ( "index1.jsp")
)
</ Script>
<%
String sn, sn1;
String e1;
String name1;
String e2;
String week [][]= new String [9] [8];
Int m1 and m2;
Sn = request.getParameter ( "guidelinks");
If (sn! = Null) (
Session.setAttribute ( "SN" sn);
Sn1 = (String) session.getAttribute ( "SN");
Else ()
Sn1 = (String) session.getAttribute ( "SN");)
%>
No. <%% sn1 => weeks multimedia classrooms single booking
<% @ Page language = "java" import = "java.sql .*"%>
<%
ResultSet Rs = null;
For (int i = 0; i <= 8; i + +)
For (int j = 0; j <= 7; j + +)
Week [i] [j] = "";
Week [0] [1] = "Monday";
Week [0] [2] = "Tuesday";
Week [0] [3] = "Wednesday";
Week [0] [4] = "Thursday";
Week [0] [5] = "Friday";
Week [0] [6] = "Saturday";
Week [0] [7] = "Sunday";
For (int i = 1; i <= 8; i + +)
Week [i] [0] = "" + i + "Festival";
Try (
Rs = showBean.executeQuery ( "SELECT * FROM guestbook" + sn1);
While (Rs.next ()) (
E1 = Rs.getString (the "week");
Name1 = Rs.getString ( "name");
E2 = Rs.getString ( "jie");
Int k = Integer.parseInt (e1);
Int l = Integer.parseInt (e2);
Week [l] [k] = name1;
)
Rs.close ();
) Catch (Exception e) (
System.out.println (e.toString ());
)
ShowBean.closeConn ();
%>
<% Out.print ( "I want to reserve");%>
<table Border='1' cellspacing='0' width='632' bgcolor='#ffffff bordercolorlight='red' bordercolordark='red'>
<% For (m1 = 0; m1 <= 8; m1 + +) (%>
<tr>
<% For (m2 = 0; m2 <= 7; m2 + +) (%>
<td Bgcolor='#33ccff'> <% = week [m1] [m2]%> </ td>
<%)%>
<tr>
<%)%>
</ Table>
Certain production
(3) add.jsp to fill appointments for teachers to single ok_add.jsp transfer form data.
The original code below, the function valiform () client for the certification form.
<% @ Page contentType = "text / html; gb2312 charset ="%>
<head>
<script LANGUAGE="JavaScript">
Function valiform () (
If (document.form1.content.value ==""){
Alert ( "Please type the subject!");
Document.form1.content.focus ();
Return false;
)
Else if (document.form1.name.value ==""){
Alert ( "Please enter names!");
Document.form1.name.focus ();
Return false;
)
Else if (document.form1.week.value ==""){
Alert ( "Please enter weeks!");
Document.form1.week.focus ();
Return false;
)
Else if (document.form1.jie.value ==""){
Alert ( "Please enter the festival!");
Document.form1.jie.focus ();
Return false;
)
)
</ Script>
</ Head>
<body>
<form METHOD=POST action="ok_add.jsp" name=form1 onSubmit="return valiform()">
Single-booking
Reservation alone can not be changed, please carefully fill!
<table Width='60%' height='120'>
<tr>
<td> Name: <input TYPE = "text" name = "name" value = ""> </ td>
</ Tr>
<tr>
<td> Week:
<select Name="week" size="1">
<option Style="color: #000000" value="1" selected> Monday </ option>
<option Style="color: #000000" value="2"> Tuesday </ option>
<option Style="color: #000000" value="3"> Wednesday </ option>
<option Style="color: #000000" value="4"> Thursday </ option>
<option Style="color: #000000" value="5"> Friday </ option>
<option Style="color: #000000" value="6"> Saturday </ option>
<option Style="color: #000000" value="7"> Sunday </ option>
</ Select>
</ Td>
<tr>
<td> Sections: <select name = "jie" size = "1">
<option Style="color: #000000" value="1" selected> the first quarter </ option>
<option Style="color: #000000" value="2"> section </ option>
<option Style="color: #000000" value="3"> the third quarter </ option>
<option Style="color: #000000" value="4"> IV </ option>
<option Style="color: #000000" value="5"> Section V </ option>
<option Style="color: #000000" value="6"> VI </ option>
<option Style="color: #000000" value="7"> Section VII </ option>
<option Style="color: #000000" value="8"> VIII </ option>
</ Select>
</ Td>
</ Td>
</ Tr>
<tr>
<td> Topics: <input type "text" name = "content" value =""></ td>
</ Tr>
<tr>
<td Align="center"> <input TYPE="submit" size="4" value="æäº¤" class="buttonface">
<input TYPE="reset" size="4" value="é‡å†™" class="buttonface"> </ td>
</ Tr>
</ Table>
</ Form>
</ Body>
(4) ok_add.jsp documents will be teachers appointment data into the database and refresh index1.jsp
<head>
<% @ Page contentType = "text / html; gb2312 charset ="%>
</ Head>
<% @ Page language = "java" import = "java.sql .*"%>
<%
Int i = 0;
String name = new String (request.getParameter ( "name"). GetBytes ( "8859_1"));
String em = new String (request.getParameter ( "week"). GetBytes ( "8859_1"));
String em2 = new String (request.getParameter ( "jie"). GetBytes ( "8859_1"));
String content = new String (request.getParameter ( "content"). GetBytes ( "8859_1"));
String sn = (String) session.getAttribute ( "SN");
String sql = "select * from guestbook" + sn;
ResultSet rs = addBean.executeQuery (sql);
While (rs.next ()) (
String ee = rs.getString (the "week");
String ee1 = rs.getString ( "jie");
If ((em.equals (ee ))&&( em2.equals (ee1))) (
I = 1;
Break;
)
)
Rs.close ();
If (i == 0) (
String strSQL = "insert into guestbook" sn + + "(name, week, jie, content) values ( '" + name + "','" em + + + "','"+ em2 +"','"
Content + "')";
AddBean.executeUpdate (strSQL);
Out.print ( "Your reservation has been saved to the database, thank you!");
) Else if (i == 1) (
If (em.equals ( "7")) (out.print ( "Sunday" + "" + em2 + "section, it was booking, please re-fill single !!");
Else ()
Out.print ( "a week" em + + "" + em2 + "section, it was booking, please re-fill single !!");
)
)
AddBean.close ();
%>
<body Onload="load2()">
<script Language=javascript>
Function load2 () (
Opener.setTimeout ( "submit11 ()", 1500)
Self.setTimeout ( "exit ()", 1500)
)
Function exit () (
Window.close ()
)
</ Script>
</ Body>
(5) dingdan.java documents used to connect databases
Package dingdan; import java.sql .*; public class dingdan (String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver" String sConnStr = "jdbc: odbc: dingdan"; private Connection conn = null; private Statement stmt = null; ResultSet rs = null; public dingdan () (try (Class.forName (sDBDriver);) catch (java.lang.ClassNotFoundException e) (System.err.println ( "dingdan ():" + e.getMessage ()); )) public ResultSet executeQuery (String sql) (try (conn = DriverManager.getConnection (sConnStr); stmt = conn.createStatement (); rs = stmt.executeQuery (sql);) catch (SQLException ex) (System.err.println ( "aq1.executeQuery:" + ex.getMessage ());) return rs;) public void executeUpdate (String sql) (stmt = null; try (conn = DriverManager.getConnection (sConnStr); stmt = conn.createStatement () ; stmt.executeUpdate (sql);) catch (SQLException ex) (System.err.println ( "aq2.executeQuery:" + ex.getMessage ());)) public void closeStmt () (try (stmt.close ()
catch (SQLException e) (e.printStackTrace ();)) public void closeConn () (try (conn.close ();) catch (SQLException e) (e.printStackTrace ();)))
6, compile documents dingdan.java
In order to use dingdan.java, you must use a command line javac compiler of this. Java document.
Will be compiled dingdan.class documents copied to the previously created
C: \ Tomcat 5.0 \ webapps \ yyd \ WEB-INF \ classes \ dingdan under.
7, running
Will be dingdan.html, index1.jsp, add.jsp, ok_add.jsp four documents on c; \ Tomcat 5.0 \ wepapps \ ydd,
Start Tomcat, in the browser address bar type http://127.0.0.1:8080/ydd/dingdan.jsp.
↑ Back
Tags: examples






