0% found this document useful (0 votes)
2 views

Adv Java 1.4 Exercise Guide - JSP Syntax

This document is a guide for creating a Hello World application using JSP syntax in Eclipse IDE. It includes step-by-step instructions for setting up a web application, creating JSP files, and displaying messages with JSP expressions. The guide concludes with instructions for running the application on a server and viewing the output in a web browser.

Uploaded by

Nandini Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Adv Java 1.4 Exercise Guide - JSP Syntax

This document is a guide for creating a Hello World application using JSP syntax in Eclipse IDE. It includes step-by-step instructions for setting up a web application, creating JSP files, and displaying messages with JSP expressions. The guide concludes with instructions for running the application on a server and viewing the output in a web browser.

Uploaded by

Nandini Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Module 1 Exercise Guide

Lab 1: JSP Syntax


Advanced Java Programming

© Copyright LearnQuest 2023.


This document may not be reproduced in whole or in part without the prior written permission of LearnQuest.
Introduction
In the following two exercises, you will use JSP Syntax to build a Hello World application.

Exercise 1: Create a Web Application using JSP


1. Open your lab.

2. On the desktop, double-click the Eclipse icon to open Eclipse IDE. (You may have to scroll down
using the right side scroll to see the Eclipse icon.) Click Launch Anyway if a warning box appears.

3. In the Eclipse IDE Launcher window, click Launch to select the default workspace.

4. When Eclipse opens, click File > New > Dynamic Web Project.

5. Name the application as MyJSPApp.

6. Click the New Runtime button at the right side.

7. Expand Apache.

© Copyright LearnQuest 2023.


This document may not be reproduced in whole or in part without the prior written permission of LearnQuest.
8. Select Apache Tomcat 10.1 from the list of available Apache Tomcat servers and click Next.

9. In the next window, click Browse and select the location of Tomcat installation Other Locations >
Computer > tmp > apache-tomcat-10.1.10 and click Open (you may have to scroll down to see
the Open button).

10. Click Finish.

© Copyright LearnQuest 2023.


This document may not be reproduced in whole or in part without the prior written permission of LearnQuest.
11. Back on the New Dynamic Web Project window, click Next at the bottom.

12. On the Java configuration page, click Next at the bottom.

13. On the Web Module page, select the box for “Generate web.xml deployment description” and
click Finish.

© Copyright LearnQuest 2023.


This document may not be reproduced in whole or in part without the prior written permission of LearnQuest.
14. On the left side of the Eclipse window, click the Restore icon to open your Project Explorer pane.

15. Now that you see your project in the Project Explorer pane, expand MyJSP App > src > main >
webapp.

16. Right click on webapp and select New > JSP File.

© Copyright LearnQuest 2023.


This document may not be reproduced in whole or in part without the prior written permission of LearnQuest.
17. Name the file index.jsp and click Finish.

18. Right click on webapp and select New > JSP File.

19. Name the file header.jsp and click Finish.

20. Repeat the steps above to add a footer.jsp file.

21. The new jsp files open to the right of the Project Explorer pane of Eclipse. (Note: You can close the
Welcome pane and the Outline pane to give yourself more room if you like.)

22. Click on the index.jsp file tab for the next part of this lab.

© Copyright LearnQuest 2023.


This document may not be reproduced in whole or in part without the prior written permission of LearnQuest.
Exercise 2: Display a message
Now, we will utilize JSP expression to display the message "Welcome to JSP."

1. In the index.jsp file, import the "java.util.Date" class using the @page directive by typing the
following code on line 3:

<!-- Directive tag -->


<%@ page import=”java.util.Date”%>

2. Move down to the bottom of the <body> and add a scriptlet to display the current date on the
page, and add a line break:

Current date and time


<%=new Date()%>
<br>

3. Just after the <body> tag, add the following @include directive to include a header.jsp file:

<%@ include file=”header.jsp”%>

© Copyright LearnQuest 2023.


This document may not be reproduced in whole or in part without the prior written permission of LearnQuest.
4. Hit Enter to go to the next line and add a level 3 header, a scriptlet that says “Welcome to JSP”,
and a line break:

<h3>Hello World!</h3>
<%=”Welcome to JSP”%>
<br>

5. Now, add more scriptlets to print numbers from 1 to 5. On the line after the line break, enter:

<p>
<% // Start of Scriptlet
for (int I = 1; I <= 5; i++) {
%>
<p><%=i%></p>
<% // End of for loop scriptlet
}
%>

6. Use the @include directive at the end of the body to include the footer.jsp file:

<%@ include file=”footer.jsp”%>

© Copyright LearnQuest 2023.


This document may not be reproduced in whole or in part without the prior written permission of LearnQuest.
7. The final code of index.jsp should look like this:

8. Click the Save icon in the toolbar to save your changes.

9. Click the header.jsp file tab to open it.

10. Inside the body, add a level 1 header that says “THIS IS THE HEADER.”

<h1>THIS IS THE HEADER</h1>

11. Click the Save icon in the toolbar to save your changes.

© Copyright LearnQuest 2023.


This document may not be reproduced in whole or in part without the prior written permission of LearnQuest.
12. Final code of header.jsp should look like this.

13. Click the footer.jsp file tab to open it.

14. Inside the body, add a level 1 header that says “THIS IS THE FOOTER.”

<h1>THIS IS THE FOOTER</h1>

15. Click the Save icon in the toolbar to save your changes.

16. Final code of footer.jsp should look like this.

© Copyright LearnQuest 2023.


This document may not be reproduced in whole or in part without the prior written permission of LearnQuest.
17. In the left Project Explorer pane, right-click index.jsp and select Run As > Run on Server.

18. Select a server: Expand Apache and select Tomcat v10.1 Server and click Finish (you may have to
scroll down to find the Finish button).

19. After the script runs, a Firefox window will open, displaying your index.jsp page. Your output
should look like the following image:

**End of lab

© Copyright LearnQuest 2023.


This document may not be reproduced in whole or in part without the prior written permission of LearnQuest.

You might also like