Lecture1_Java Server Pages
Lecture1_Java Server Pages
Instructor: CUONGPNB1
Know about
Java Server
Pages (JSP)
Can use JSP
to build Web
application
JSP INTRODUCTION
JSP vs Servlet:
Code snippet
<%
String username = "alliant";
out.println(username);
%>
Code snippet
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Directive tag</title>
</head>
<body>
<%@include file="Header.jsp"%>
<hr />
<h2>This is main content</h2>
<h4 style="color: red"><%=new Date()%></h4>
<hr />
<%@include file="Footer.jsp"%>
</body>
</html>
Code snippet
<h3 align="left">TRAINEE FULL INFORMATION</h3>
<table>
<tr>
<th>Id</th>
<th>Trainee Name</th>
<th>Salary</th>
</tr>
<!-- traineeData: a list of trainee -->
<c:forEach items="${traineeData}" var="trainee">
<tr>
<td>${trainee.getId()}</td>
<td>${trainee.getName()}</td>
<td>${trainee.getSalary()}</td>
</tr>
</c:forEach>
</table>
©FPT SOFTWARE - Corporate Training Center - Internal Use 18
Action tags (1/2)
Action (<%action... %>
JSP Actions lets you perform some action.
Provide access to common tasks performed in a JSP:
• Including content from other resources.
• Forwarding the user to another page.
• Interacting with JavaBeans.
Delimited by <jsp:action> and </jsp:action>.
side-bar
content
2. If the included file is changed but not the JSP which is including it then the changes
will reflect only when we use include action tag. The changes will not reflect if you
are using include.
3. Syntax difference.
4. When using include action tag we can also pass the parameters to the included page
by using param action tag but in case of include directive it’s not possible.
Code snippet
<jsp:useBean id="account" class="ctc.fr.atjb.bean.Account">
<jsp:setProperty property="emailAddress" name="account" />
<jsp:setProperty property="password" name="account" />
<h3>
Welcome,
<jsp:getProperty property="emailAddress" name="account" /><br>
</h3>
You have been successfully Logged in...
</jsp:useBean>
<!--ViewStock.jsp -->
<%
String stockCode = request.getParameter("stockCode");
String stockName = request.getParameter("stockName");
String description = request.getParameter("des");
%>
©FPT SOFTWARE - Corporate Training Center - Internal Use 34
Implicit Objects
Response