Download PowerPoint Presentation - CSIE -NCKU

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Tomcat, JSP, Servlet Tutorial
Outline





Setting Up the JSP Environment
Servlet
JSP
Setting Up the MySQL Environment
e-commerce web application
Installing the Java Software
Development Kit

JDK 5.0 Update 4 (SDK/JDK)



Choose SDK not JRE
JSP requires a compiler in SDK
http://java.sun.com/j2se/1.5.0/downloa
d.jsp
Set JAVA_HOME environment
variable

Set JAVA_HOME to the location of Java
SDK (C:\Program Files\Java\jdk1.5.0_04)
Install Tomcat 5.5

5.5.9

Binary


5.5.9 exe
http://jakarta.apache.org/site/download
s/downloads_tomcat-5.cgi
Set CATALINA_HOME
environment variable

Set CATALINA_HOME to the location of
Tomcat (C:\Program Files\Apache
Software Foundation\Tomcat 5.5)
Example Web Application
Overview

Start Tomcat by bin/tomcat5w
Outline





Setting Up the JSP Environment
Servlet
JSP
Setting Up the MySQL Environment
e-commerce web application
Download the source code of
servlet HelloWorldExample.java

http://140.116.82.24/HelloWorldExampl
e.java
Deploy a servlet – Step 1




Write the servlet Java code
Copy Tomcat 5.5\common\lib\servletapi.jar to jre1.5.0_04\lib\ext
Compile javac HelloWorldExample.java
Copy HelloWorldExample.class to
Tomcat 5.5\webapps\ROOT\WEBINF\classes
Deploy a servlet – Step 2

Add servlet mapping to Tomcat
5.5\webapps\ROOT\WEB-INF\web.xml
HelloWorldExample servlet

http://140.116.82.24/example_servlet/
HelloWorldExample
Outline





Setting Up the JSP Environment
Servlet
JSP
Setting Up the MySQL Environment
e-commerce web application
Write JSP code



Write JSP pages then deploy them as
html files
<% %> contains Java code
Copy JSP code from
http://140.116.82.24/jsp_code.htm
Deploy JSP


Save JSP as HelloWorld.jsp to Tomcat
5.5\webapps\ROOT
See the result at
http://140.116.82.24/HelloWorld.jsp
Result of a JSP page


The same result as the servlet replies
Much easier
Outline





Setting Up the JSP Environment
Servlet
JSP
Setting Up the MySQL Environment
e-commerce web application
Install MySQL 4.1


Windows (x86) 4.1.13a
http://dev.mysql.com/downloads/mysql/
4.1.html
Configure root password

\bin\mysql –u root




USE mysql
UPDATE user SET
password=password('root3394') where
user='root';
FLUSH PRIVILEGES;
quit
Install EMS MySQL Manager 3


Install EMS MySQL Manager 3
http://www.sqlmanager.net/
Create a database table
Handset table

Create a handset table with fields



manufacturer
model_name
price
Data in the handset table

EMS lets you to input data easily
Outline





Setting Up the JSP Environment
Servlet
JSP
Setting Up the MySQL Environment
e-commerce web application
Use MySQL on Tomcat by
MySQL JDBC Driver



Source and Binaries (zip)
http://dev.mysql.com/downloads/conne
ctor/j/3.1.html
Input mysql-connector-java-3.1.10bin.jar to ROOT\WEB-INF\lib
Result of HandsetList.jsp

http://140.116.82.24/HandsetList.jsp
Reference

JavaServer Pages By Hans Bergsten
Related documents