You are on page 1of 18

CS5054NI

ADVANCED PROGRAMMING
AND
TECHNOLOGIES
Week 4
Introduction on JSP

ADVANCED PROGRAMMING AND TECHNOLOGIES Prithivi Maharjan


Tutorial Task
In this tutorial we will convert the html files into JSP. After that we will utilize JSP Implicit
Objects and JSP Tags

ADVANCED PROGRAMMING AND TECHNOLOGIES August 7, 2022 | 2


Creating JSP file
Create a new JSP file inside
pages folder with name
register.jsp

ADVANCED PROGRAMMING AND TECHNOLOGIES August 7, 2022 | 3


Creating JSP file
• As we can see we have created a new file named register.jsp

ADVANCED PROGRAMMING AND TECHNOLOGIES August 7, 2022 | 4


Creating JSP file
• Now copy all the codes of register.html and paste it below the line number
directive tag - <%@ … %> (starting from line number 3 where <!DOCTYPE
html> is located).

ADVANCED PROGRAMMING AND TECHNOLOGIES August 7, 2022 | 5


Creating JSP file
• Now we can delete the register.html file (Fig 1)
• Similarly create JSP file for login and welcome HTML files and utilize the html
code to JSP as we have done before. (Fig 2)
Fig 1: Current Files Fig 2: Updated Files

ADVANCED PROGRAMMING AND TECHNOLOGIES August 7, 2022 | 6


Creating JSP file
In register.jsp file add the code shown below the <div class=“container”>.
• By this approach we can get the message from Java Servlet file

ADVANCED PROGRAMMING AND TECHNOLOGIES August 7, 2022 | 7


ResigterServlet.java
As we can see we can send message according to our needs to the different
pages with the help of request and response.

ADVANCED PROGRAMMING AND TECHNOLOGIES August 7, 2022 | 8


String Utilization
Now we will add all the strings used in our RegisterServlet.java file to
StringUtils.java

ADVANCED PROGRAMMING AND TECHNOLOGIES August 7, 2022 | 9


String Utilization
Put all the string parameters in the StringUtils.java file so that we can easily
manage and reuse them when needed.

ADVANCED PROGRAMMING AND TECHNOLOGIES August 7, 2022 | 10


String Utilization
RegisterServlet.java
- Utilizing StringUtils.java parameters string variables.

ADVANCED PROGRAMMING AND TECHNOLOGIES August 7, 2022 | 11


String Utilization
StringUtils.java
- As before adding the messages and route string in this file.

ADVANCED PROGRAMMING AND TECHNOLOGIES August 7, 2022 | 12


String Utilization
RegisterServlet.java
- Utilizing StringUtils.java message and route string variables.

ADVANCED PROGRAMMING AND TECHNOLOGIES August 7, 2022 | 13


String Utilization
RegisterServlet.java
- Utilizing StringUtils.java message and route string variables.

ADVANCED PROGRAMMING AND TECHNOLOGIES August 7, 2022 | 14


String Utilization
register.jsp
- Utilizing StringUtils.java route string variables.

ADVANCED PROGRAMMING AND TECHNOLOGIES August 7, 2022 | 15


Output
Error message when MySQL server is off

Step 1: Stopping MySQL server.

Step 2: Error message shown as expected on submit.


ADVANCED PROGRAMMING AND TECHNOLOGIES August 7, 2022 | 16
Output
Successfully redirected to login page when server is started
Step 2: Adding data
Step 3: Redirected to login after success.

Step 1: Starting Server

ADVANCED PROGRAMMING AND TECHNOLOGIES August 7, 2022 | 17


Thank You

You might also like