LDSTechForumProjects

Introduction to JSP

Introduction to Java Server Pages

Prerequisites

  • Installed LDSTech IDE (or other equivalent)
  • Basic knowledge of the Java language.
  • Basic knowledge of HTML syntax and structure.
  • Basic knowledge of Java Servlets and web application development.
  • A laptop running Windows, Linux, or Mac OS.
  • A desire to learn.

Slide Deck

Media:IntroductionToJSP.ppt

Overview

Java Server Pages (commonly called JSP) have long been a part of the Java EE specification, is a mature technology for rendering web pages, and provides an integral role in MVC frameworks. This training will cover the following basic concepts:

  • How Java Server Pages extend and simplify servlets in the generation of HTML pages.
  • Fundamentals of JSP scripting:
    • Directives - Attributes that customize the generation of a JSP servlet as well as it's behavior.
    • Declarations - Java variables and functions that are inserted into the generated JSP servlet.
    • Expressions - Java statements that are evaluated and printed to the JSP's HTML output.
    • Scriptlets - Java statements that are inserted into the JSP's generated service method.
      • Implicit Objects - How to make use of the objects implicitly available to scriptlets.
    • Error Handling - How to catch and handle exceptions thrown from a JSP.

Video Presentation

Get Adobe Flash player

Lab 1: JSP Servlet Compilation

  1. Download the lab project media:jsp-intro-training-labs.zip
  2. Unzip and import the project into your IDE
    • If using the LDSTech IDE you can import the project by going to File->Import...
    • Choose Maven->Existing Maven Project
    • Select your unzipped project folder
    • Click "Finish".
  3. Set up a Tomcat 6 web server in your IDE (if one is not already available)
  4. Deploy the project to your Tomcat 6 web server
  5. Examine the example JSP at src/main/webapp/labs/Lab1-JspExample.jsp
    • It's okay if you don't understand all the syntax at this point.
  6. Test the page by going to the home page of the deployed app and clicking the Lab 1 link
  7. Return to the home page and view the source of the generated servlet by clicking "Solution to Lab 1: JSP Servlet Generation."

Lab 1: Solution

Video Presentation

Get Adobe Flash player

JSP Directives

Video Presentation

Get Adobe Flash player

Lab 2: Hello World in JSP

  1. Follow the instructions in the file src/main/webapp/labs/Lab2-HelloWorld.jsp
  2. Test your page by going to the home page of the deployed app and clicking the Lab 2 link
  3. You may also compare your solution to the one provided on the home page.

Lab 2: Solution

Video Presentation

Get Adobe Flash player

JSP Expressions, Scriptlets, and Error Pages

Video Presentation

Get Adobe Flash player

Lab 3: A JSP Calendar

  1. Follow the instructions in the file src/main/webapp/labs/Lab3-JspCalendar.jsp
    • Note: if you run out of time, you may skip steps 10-13.
  2. Test your page by going to the home page of the deployed app and clicking the Lab 3 link
  3. You may also compare your solution to the one provided on the home page.

Lab 3: Solution

Video Presentation

Get Adobe Flash player

Using Maven to Compile JSPs

Video Presentation

Get Adobe Flash player

Lab 4: Pre-compiling JSPs with Maven

  1. Launch the Stack Starter
  2. Select "Web Application" as your project type with options similar to the following:
    • Project Name: jsp-training-lab4
    • Package Name: org.lds.stack.training.jsp.lab4
    • Project Location: C:\Temp\jsp-training-lab4
  3. Click Next and select the Security property group, modify the following:
    • LDS Account Authentication: Off
  4. Select the Service Layer property group, and modify the following:
    • Use Database: Off
  5. Click Next and Build the project.
  6. When the build is complete, import the project into your IDE
  7. Copy the contents of the lab file src/main/webapp/labs/Lab1-JspExample.jsp into your Stack project's file web/src/main/webapp/WEB-INF/views/index.jsp.
  8. Build the project with maven.
    • In LDSTech IDE, refresh the target directory until the compiled files show up.
  9. Examine the maven build log to watch your JSP being compiled.
  10. Open the file at web/target/jsp-source/jsp/WEB_002dINF/views/index_jsp.java
  11. Experiment how modifying the index.jsp file affects the contents of index_jsp.java

Want to learn more?

See Java Stack Training | LDS Java Stack

This page was last modified on 12 July 2013, at 19:29.

Note: Content found in this wiki may not always reflect official Church information. See Terms of Use.