Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Faculty of ESBE  ANP 
 
 
Dr. Perry XIAO Copyright © 2007-2012, London South Bank University 1 
Lab 3: Data Display Through WWW using JSP/MySQL 
 
 
The aim of this lab session is to understand how to display data through WWW pages using 
JSP/MySQL.  
 
Equipments: 
Two networked PCs with WindowsXP operating systems, Java software, MySQL Community 
Server software, Tomcat software, logbook, and a USB memory stick for saving your work. 
 
Exercises 1: 
 
1. Boot up a WindowsXP computer, login as user “link”. To download Java SE JDK 7, just 
go to http://www.oracle.com/technetwork/java/javase/downloads/index.html, and 
follow the instructions to download an install Java JDK 7. 
2. by default, Java should be installed in C:\program files\java folder. To Test Java, from 
a MS-DOS prompt, type 
 
C:\java  –version 
 
 
Exercises 2: 
 
1. To download Tomcat 7 from http://tomcat.apache.org/, follow the instructions to download 
a file called: apache-tomcat-7.0.26.exe, and save it to your desktop and double click to run 
it. 
2. To test that Tomcat is running, from another Windows XP computer, open a web browser, 
and type in following URL: http://xxx.xxx.xxx.xxx:8080, where xxx.xxx.xxx.xxx is the 
first Windows XP computer’s IP address or domain name. If everything is fine, you should 
be able to see a web page such as this. 
 
 
Faculty of ESBE  ANP 
 
 
Dr. Perry XIAO Copyright © 2007-2012, London South Bank University 2 
 
3. You can start, stop and configure the Tomcat server from your Desktop, find out how. 
 
 
 
Exercises 3: 
 
1. To use database in JSP files, first you need to install the MySQL database. Goto  
http://www.mysql.com/downloads/mysql/, and download and install the latest 
MySQL database. 
2. Second, you will need to install Java JDBC driver. Go to 
http://www.mysql.com/downloads/connector/j/, and download Connector/J.  
3. This is just an Java JAR file, should be called: 
 
mysql-connector-java-5.1.18.zip 
 
4. Unzip the file, and then copy the file mysql-connector-java-5.1.18-bin.jar to 
following directories. 
 
C:\program files\java\jdk1.6.0\lib 
C:\program files\java\jdk1.6.0\jre\lib 
C:\program files\java\jdk1.6.0\jre\lib\ext 
C:\apache-tomcat-7.0.2\lib 
C:\apache-tomcat-7.0.2\webapps\test\WEB-INF\lib 
 
5. Next, start MySQL database service. 
 
Exercises 4: 
 
1. To create a JSP web application, first you need to create a web application folder structure 
under the C:\apache-tomcat-7.0.2\webapps\ directory. In this case, we create a web 
application called: “test”, following is its structure. 
 
 
C:\apache-tomcat-7.0.2\webapps\ 
                                                                      \test\ 
                                                                                \WEB-INF 
                                                                                              \classes 
                                                                                               \lib 
 
 
2. Create a “jdbcread0.jsp” file in the C:\apache-tomcat-7.0.2\webapps\test folder, and put 
following lines into the file. 
 
<%@page contentType="text/html"%> 
<%@page pageEncoding="UTF-8"%> 
 
JSP Page 
 
 
Faculty of ESBE  ANP 
 
 
Dr. Perry XIAO Copyright © 2007-2012, London South Bank University 3 
<%@page import = "java.sql.*"%> 
<% 
  try{ 
        Class.forName("com.mysql.jdbc.Driver").newInstance(); 
        Connection connection=DriverManager.getConnection("jdbc:mysql://localhost/test", “root”, 
“letmein”); 
 
        Statement statement=connection.createStatement(); 
        String query; 
        query="SELECT * FROM Contacts"; 
        ResultSet resultSet=statement.executeQuery(query); 
        out.println("Contacts
ID Firstname Surname Address
"+"=====================
"); while (resultSet.next()){ out.println(resultSet.getString(1)+" "); out.println(resultSet.getString(2)+" "); out.println(resultSet.getString(3)+" "); out.println(resultSet.getString(4)+"
"); } } catch (Exception e) { out.println(e.toString()); } %> 3. From another Windows XP computer, open a web browser, and type in following URL: http://xxx.xxx.xxx.xxx:8080/test/jdbcread0.jsp, where xxx.xxx.xxx.xxx is the Windows XP computer’s IP address or domain name. If everything is fine, you should be able to see a web page showing the Contacts table. References: 1. http://java.sun.com 2. http://tomcat.apache.org/ 3. http://www.linux-sxs.org/internet_serving/ 4. http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPIntro.html 5. http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets.html 6. http://www.jsptut.com/ 7. http://eent3.sbu.ac.uk/staff/xiaop 8. David Harms, “JSP, Servlets, and MySQL”, ISBN: 0764547879, M&T Book, 2001 (http://www.covecomm.com/java). 9. Barry Burd, JSP: JavaServer Pages, ISBN:0764535358, M & T Books, 2001 Questions: 1. Define the terms of CGI, Perl, ASP, JSP, Servlet. Faculty of ESBE ANP Dr. Perry XIAO Copyright © 2007-2012, London South Bank University 4 2. What are the differences between server side programs and client side programs? 3. What is Tomcat, and what is Apache web server?