servlet and tomcat tutorial ect 7130. download tomcat e.org/tomcat/tomcat-5/v5.5.28/bin/apache-...
TRANSCRIPT
![Page 1: Servlet and Tomcat Tutorial ECT 7130. Download Tomcat e.org/tomcat/tomcat-5/v5.5.28/bin/apache- tomcat-5.5.28.zip](https://reader036.vdocuments.mx/reader036/viewer/2022081205/56649db35503460f94aa3493/html5/thumbnails/1.jpg)
Servlet and Tomcat Tutorial
ECT 7130
![Page 2: Servlet and Tomcat Tutorial ECT 7130. Download Tomcat e.org/tomcat/tomcat-5/v5.5.28/bin/apache- tomcat-5.5.28.zip](https://reader036.vdocuments.mx/reader036/viewer/2022081205/56649db35503460f94aa3493/html5/thumbnails/2.jpg)
Download Tomcat
• http://ftp.cuhk.edu.hk/pub/packages/apache.org/tomcat/tomcat-5/v5.5.28/bin/apache-tomcat-5.5.28.zip
• Put under C:\ and unzip to C:\apache-tomcat-5.5.28
![Page 3: Servlet and Tomcat Tutorial ECT 7130. Download Tomcat e.org/tomcat/tomcat-5/v5.5.28/bin/apache- tomcat-5.5.28.zip](https://reader036.vdocuments.mx/reader036/viewer/2022081205/56649db35503460f94aa3493/html5/thumbnails/3.jpg)
Starting and Stopping Tomcat
• In command line window, set JAVA_HOME=c:\Program Files\Java\jdk1.5.0_03 (depends on your jdk directory name, for example, maybe yours is jdk1.6.x_xx)
• C:\apache-tomcat-5.5.28\bin>startup
• C:\apache-tomcat-5.5.28\bin>shutdown
• Open a browser and type inhttp://localhost:8080
![Page 4: Servlet and Tomcat Tutorial ECT 7130. Download Tomcat e.org/tomcat/tomcat-5/v5.5.28/bin/apache- tomcat-5.5.28.zip](https://reader036.vdocuments.mx/reader036/viewer/2022081205/56649db35503460f94aa3493/html5/thumbnails/4.jpg)
Web Application Directory Structurewebapps
*.jsp
*.html
liangweb
WEB-INF
classes
Static files, such as HTML files and JSP files in the directory that is the document root of your Web Application
*.class
lib
*.jar
web.xml
Packages (e.g., chapter35)
*.class
![Page 5: Servlet and Tomcat Tutorial ECT 7130. Download Tomcat e.org/tomcat/tomcat-5/v5.5.28/bin/apache- tomcat-5.5.28.zip](https://reader036.vdocuments.mx/reader036/viewer/2022081205/56649db35503460f94aa3493/html5/thumbnails/5.jpg)
Compiling Servlets
• Set classpath=%classpath%;c:\apache-tomcat-5.5.28\common\lib\servlet-api.jar
• Create directoryc:\apache-tomcat-5.5.28\webapps\liangweb\WEB-INF\classes
• Copy slide/book/FirstServlet.class into c:\apache-tomcat-5.5.28\webapps\liangweb\WEB-INF\classes
![Page 6: Servlet and Tomcat Tutorial ECT 7130. Download Tomcat e.org/tomcat/tomcat-5/v5.5.28/bin/apache- tomcat-5.5.28.zip](https://reader036.vdocuments.mx/reader036/viewer/2022081205/56649db35503460f94aa3493/html5/thumbnails/6.jpg)
• Download www.cs.armstrong.edu/liang/intro6e/supplement/web.xml to
c:\apache-tomcat-5.5.28\webapps\liangweb\WEB-INF
• Run by typing
http://localhost:8080/liangweb/FirstServlet
![Page 7: Servlet and Tomcat Tutorial ECT 7130. Download Tomcat e.org/tomcat/tomcat-5/v5.5.28/bin/apache- tomcat-5.5.28.zip](https://reader036.vdocuments.mx/reader036/viewer/2022081205/56649db35503460f94aa3493/html5/thumbnails/7.jpg)
For JDBC Programs• Create a directory liangweb/META-INF
• Create a file “context.xml” with the following content
<Context path="/liangweb" docBase="liangweb" debug="5“ reloadable="true" crossContext="true">
<Resource name="jdbc/TestDB" auth="Container“ type="javax.sql.DataSource” driverClassName="com.mysql.jdbc.Driver url="jdbc:mysql://localhost;DatabaseName=javabook" username="scott" password="tiger"
maxActive="300" maxIdle="30" maxWait="10000" />
</Context>
![Page 8: Servlet and Tomcat Tutorial ECT 7130. Download Tomcat e.org/tomcat/tomcat-5/v5.5.28/bin/apache- tomcat-5.5.28.zip](https://reader036.vdocuments.mx/reader036/viewer/2022081205/56649db35503460f94aa3493/html5/thumbnails/8.jpg)
• Put mysqljdbc.jar under apache-tomcat-5.5.28/common/lib/
• You have to startup your MySQL database (or MySQL service) with “net start mysql”
![Page 9: Servlet and Tomcat Tutorial ECT 7130. Download Tomcat e.org/tomcat/tomcat-5/v5.5.28/bin/apache- tomcat-5.5.28.zip](https://reader036.vdocuments.mx/reader036/viewer/2022081205/56649db35503460f94aa3493/html5/thumbnails/9.jpg)
Run JDBC Servlet Programs• Under slide/book, you can find SimpleRegistration.html and
SimpleRegistration.class. Do the following tasks:
1. Put the html file under apache-tomcat/webapps/liangweb. Put the class file under apache-tomcat/webapps/liangweb/WEB-INF/classes.
2. Startup tomcat, and type the URL http://localhost:8080/liangweb/SimpleRegistration.html in a browser.
3. Test whether you can successfully insert the record you input in the form into the database.
4. Before you do that, you have to create a table "Address" with the lastname, firstname,..., zip fields in your MySQL database.
You can also test Registration.html/class, RegistrationWithCookie.html/class and RegistrationWithHttpSession.html/class in a similar way.
![Page 10: Servlet and Tomcat Tutorial ECT 7130. Download Tomcat e.org/tomcat/tomcat-5/v5.5.28/bin/apache- tomcat-5.5.28.zip](https://reader036.vdocuments.mx/reader036/viewer/2022081205/56649db35503460f94aa3493/html5/thumbnails/10.jpg)
Part II: JSP
• Startup tomcat
• Copy the following jsp files to apache-tomecat\webapps\liangweb and run
• CurrentTime.jsphttp://localhost:8080/liangweb/CurrentTime.jsp
• Factorial.jsphttp://localhost:8080/liangweb/Factorial.jsp
• ComputeLoan.html and ComputeLoan.jsp
http://localhost:8080/liangweb/ComputeLoan.html
![Page 11: Servlet and Tomcat Tutorial ECT 7130. Download Tomcat e.org/tomcat/tomcat-5/v5.5.28/bin/apache- tomcat-5.5.28.zip](https://reader036.vdocuments.mx/reader036/viewer/2022081205/56649db35503460f94aa3493/html5/thumbnails/11.jpg)
• ComputerLoan1.html (modify this file according to Page 31 of Chapter 40 ppt)
• Copy Loan.java to liangweb\WEB-INF\classes\chapter35\• Compile it into Loan.class• http://localhost:8080/liangweb/ComputerLoan1.html
• Do the same for ComputerLoan2.html + Loan.class
• Do the same for TestBeanScope.jsp + Count.class
• Do the same for FactorialBean.jsp + FactorialBean.class
• Do the same for NewFactorialBean.jsp + NewFactorialBean.class
![Page 12: Servlet and Tomcat Tutorial ECT 7130. Download Tomcat e.org/tomcat/tomcat-5/v5.5.28/bin/apache- tomcat-5.5.28.zip](https://reader036.vdocuments.mx/reader036/viewer/2022081205/56649db35503460f94aa3493/html5/thumbnails/12.jpg)
The JDBC Example
• Copy DBLogin.html, DBLoginInitialization.jsp, Table.jsp, BrowseTable.jsp to liangweb
• Copy DBBean.java to liangweb/WEB-INF/classes/chapter35 and compile it to DBBean.class
• Startup MySQL
• Run http://localhost:8080/liangweb/DBLogin.html