Introduction to JSP
Contents |
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
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
Lab 1: JSP Servlet Compilation
- Download the lab project media:jsp-intro-training-labs.zip
- 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".
- Set up a Tomcat 6 web server in your IDE (if one is not already available)
- Deploy the project to your Tomcat 6 web server
- 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.
- Test the page by going to the home page of the deployed app and clicking the Lab 1 link
- 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

JSP Directives
Video Presentation

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

JSP Expressions, Scriptlets, and Error Pages
Video Presentation

Lab 3: A JSP Calendar
- 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.
- Test your page by going to the home page of the deployed app and clicking the Lab 3 link
- You may also compare your solution to the one provided on the home page.
Lab 3: Solution
Video Presentation

Using Maven to Compile JSPs
Video Presentation

Lab 4: Pre-compiling JSPs with Maven
- Launch the Stack Starter
- 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
- Project Name:
- Click Next and select the Security property group, modify the following:
- LDS Account Authentication:
Off
- LDS Account Authentication:
- Select the Service Layer property group, and modify the following:
- Use Database:
Off
- Use Database:
- Click Next and Build the project.
- When the build is complete, import the project into your IDE
- Copy the contents of the lab file
src/main/webapp/labs/Lab1-JspExample.jspinto your Stack project's fileweb/src/main/webapp/WEB-INF/views/index.jsp. - Build the project with maven.
- In LDSTech IDE, refresh the target directory until the compiled files show up.
- Examine the maven build log to watch your JSP being compiled.
- Open the file at
web/target/jsp-source/jsp/WEB_002dINF/views/index_jsp.java - Experiment how modifying the
index.jspfile affects the contents ofindex_jsp.java
Want to learn more?
This page was last modified on 5 June 2012, at 15:53.
This page has been accessed 2,267 times.

