The Ninth Lab
JSP Programming & Tomcat
(I) JSP
Dynamic Web Pages (Web content is not fixed)
Server-Side Scripting (Server controls the Web construction)
A JSP page is basically a web page with traditional HTML and bits of Java code (Inside JSP or Outside JSP).
In a JSP page, <% ... %> encloses Java code.
a) When JSP page is called, it will be compiled (by the JSP Engine ) into a Java servlet.
JSP files along with java code are compiled into *_jsp.java and *_jsp.class files
In Tomcat, you can find those java servlet files in /apache-tomcat-X.X.XX/work/Catalina/localhost/...
b) The servlet is loaded and executed (by the Servlet Container ) to create dynamic HTML to be sent to the browser.
Tomcat is the web server and servlet container
Jasper is the JSP engine in Tomcat
Catalina is the JAVA servlet container in Tomcat
Beside Tomcat , you may also choose Jetty , Jboss(Wildfly) , and so on.
Ant is a build tool
Ant uses XML file to describe the build process.
If there is no argument:
Ant looks for a build.xml file in the current directory
Ant runs the target in the default attribute of the < project > tag.
Use "-f FILENAME" to specify the build file
We use "ant -f FILENAME all" to runs the 'all' target
(II) About PA1
a) Stop the Catalina server.
b) Delete the photoshare folder in webapps folder
c) Re-compile your code using ant
d) Re-copy the photoshare.war file to webapps folder
e) Start the Catalina server.
a) Use ps ux to show your processes
If you start the Catalina server, you should find processes with command as "java -Djava.util...."
b) Get the PIDs in the second column of those processes
b) Use kill -9 PID to terminate those processes
a) Use ls -a to check whether you have the file .bash_profile
If you do not have .bash_profile , create the .bash_profile file with content Here
b) Use source ~/.bashrc to load bash file manually
c) You can even customize the bash prompt. ( Tutorial )
For example: Include the following content into .bashrc to make prompt colorful
A sample shell script is Here
a) Download the script file update.sh
b) Change PA1DIR directory in the script file
c) Use ./update.sh to execute the shell script
The script file update.sh execute the following commands:
a) Stop the Catalina Server
b) Re-compile the Code from Photoshare
c) Remove the previous files in Tomcat
d) Copy the updated war file
e) Start the Catalina Server
Feel free to change the file to satisfy your requirements
(III) JSP Programming
You can find details about HTML Forms Here
a) Input Tag:
Input Type
Input Name: Variable Name
Input Value: Variable Value (Typed or Selected)
b) Action Attribute
Action specifies where to send the form-data
JSP file in PA1
Not required for HTML5
c) Method Attribute
GET: form data is visible
POST: submitted data is not visible
a) Use JavaBeans to get information from HTML Forms
b) Two tutorials Here and Here
c) Define properties in JavaBeans.
The first letter of property names should be in lower-case.
d) Define getPropertyName() in JavaBeans.
The first letter of property name should be translated into upper-case
e) Define setPropertyName() in JavaBeans.
The first letter of property name should be translated into upper-case
f) Use < jsp:useBean id="Variable Name" class="JavaBean Name" / > to use JavaBean classes
Three-tier Architecture (Presentation tier, Logic tier, Data tier)
Write DAO classes to conduct SQL queries
Use < %@ page import="*.*Dao" % > to import the DAO classes
(IV) Sample Code for Inserting Dates: