The Seventh Lab

JavaServer Pages

Octy 16, 2015

(I) Download Tomcat

  •         1) Download Tomcat here
                    Tomcat 8.0 or 7.0 or 6.0
                    Download the "Binary Distributions"
                            Choose zip file or tar.gz file for Linux and Mac machines
                            Choose 32-bit or 64-bit Windows zip file for Windows machines
  •         2) Unzip the compressed file
  •         3) Read RUNNING.txt file
  •         4) Check JAVA_HOME environment variable
                    In Linux and Mac machines, using echo $JAVA_HOME to check JAVA_HOME variable
                    In Windows machines, using echo %JAVA_HOME% to check JAVA_HOME variable
  •         5) Set JAVA_HOME environment variable, if the variable does not exist
                    For the Linux machines in CS Undergrad Lab:
                            a) Open the terminal
                            b) Run vim .bashrc
                            c) Click button a to enter insert mode
                            d) Add export JAVA_HOME=/usr in one line
                            e) Click button Esc to quit insert mode
                            f) Type :wq to save and quit vim
                            g) Close the terminal
                            h) Reopen the terminal and check JAVA_HOME
                    For Mac machines Tutorial
                    For Windows machines Tutorial

(II) Start Tomcat Server

  •         1) Go to Tomcat Bin Folder
                    You should be able to find the bin folder under the Tomcat
                    In the bin folder, you should be able to see files catalina.bat and
                    Go to the bin folder
  •         2) Start Tomcat Server
                    On Windows: .\catalina.bat start
                    On Linux and Mac: ./ start
                    If there is an error message about permission denied, change the file permissions
                            On Windows: use file explorer
                            On Linux and Mac: use chmod command: chmod 744 *
  •         3) Visit http://localhost:8080/ in web browser.
                    You should be able to see Tomcat welcome webpage.
  •         4) Stop Tomcat Server
                    On Windows: .\catalina.bat stop
                    On Linux and Mac: ./ stop

(III) Program with JSP

  •         1) Go to Tomcat Folder
                    You should be able to see a folder webapps
  •         2) Create a project folder under the directory webapps
                    For example, create lab7 folder under webapps directory
  •         3) Create a jsp file
                    A sample jsp file is Here
                    Save it to index.jsp file. Remove ".txt"
  •         4) Put the jsp file in the folder lab7
  •         5) Create a java class directory under the project directory
                    Go to lab7 directory
                    Create a directory WEB-INF directory under lab7
                    Then create a directory classes directory under WEB-INF
                    Finally create a directory lab7 directory under classes
  •         6) Create a java class
                    A sample java file is Here
                    Put the java file into the folder webapps/lab7/WEB-INF/classes/lab7/
  •                 Compile the java code
  •                         Use javac
  •                         You should be able to see a class file WelcomeInfo.class
  •         7) Now, there are two files in the project folder webapps/lab7
  •                 webapps/lab7/index.jsp
  •                 webapps/lab7/WEB-INF/classes/lab7/WelcomeInfo.class
  •         8) Start the Tomcast server
  •         9) Visit http://localhost:8080/lab7/index.jsp in web browser.
  •         10) Stop the Tomcast server

  •         * If you make any change on jsp and java files,
  •                 a) Recompile your jave code (Get a new class file)
  •                 b) Relaunch the Tomcast server (Stop the server and Start it again)

(IV) Exercise

  •         1) Read the jsp file.
  •         2) Understand how jsp file works.
  •         3) Modify the jsp and java file.

(V) External Reading