Workshop 7. The Include Action

Objective

The aim of this workshop is to make use of the include action tag to include the output of one file in another.

Time Available

This workshop should take no longer than 60 minutes.

The Include Action Workshop

The following demonstrates the objective of this workshop.

Demo

  1. Download the file 'include2.txt' from the following hyperlink and save it to your working directory. Change extension from 'txt' to 'jsp'.

    Download file icon

    This file is a JSP whose output we want to include in another JSP. For interest you can read the code in this JSP to see how it works.

  2. Create a new JSP called 'include1.jsp' and add the following HTML.

    <HTML>
    <HEAD>
    <TITLE>JSP Course - Request Workshop</TITLE>
    <LINK rel="stylesheet" type="text/css" href="/course.css">
    </HEAD>
    
    <BODY>
    
    
    </BODY>
    </HTML>
    
    
  3. After the opening <BODY> tag add an include action tag to include the output of "include2.jsp". To this tag add a parameter action tag that has a name attribute called "Name" and a value attribute of "YourName".

  4. Save and test your work.
  5. How does "include2.jsp" pick up the value of the parameter ?

if you couldn't get your solution to work then click the icon to display the source code. Source code icon

Tech Tips

If the JSP that is being included fails to execute then the error messages generated will be displayed as the include. Try this in the above workshop by making a mistake in the code - drop a semicolon or something.

Forward Action

The next section looks at the <jsp:forward/> action tag that allows you to redirect the workflow on the server. This is similar to the sendRedirect() method we met earlier and you may want to read this section again.

Back Next