Home »
Java programming language
Expression Language in JSP
Learn: What is Expression Language in JSP? In this post we are explaining use of EL in JSO with suitable example?
By: Vanka Manikanth, on 26 FEB 2017
Expression Language (EL) makes ease for programmers to put out the values on to the screen instead writing a print statement. So, here we provided a simple and clear example where you can understand the EL use in JSP.
index.jsp
Here we are taking the inputs from the user and triggering the action to output.jsp with a POST method.
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>EL</title>
<style type="text/css">
body{
text-align:center;
}
p{
font-size:16pt;
}
h1{
background-color:yellow;
}
</style>
</head>
<body>
<h1>EXPRESSION LANGUAGE IN JSP</h1>
<form action="output.jsp" method="post">
<p><label>USER NAME :</label>
<input type="text" name="username"></p>
<p><label>EMAIL ID :</label>
<input type="email" name="email"></p>
<p><label>GENDER : </label>
<input type="radio" name="gender" value="Male">MALE
<input type="radio" name="gender" value="Female">FEMALE</p>
<p>
<label>USER DIVISION :</label>
<select name="division" required>
<option value="">Select</option>
<option value="East">East</option>
<option value="West">West</option>
<option value="North">North</option>
<option value="south">South</option>
</select>
</p>
<button>SAVE DETAILS</button>
</form>
</body>
</html>
output.jsp
Here we are just printing out the values which are taken at the index page with a $(dollar) prefix.
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>EL</title>
</head>
<body>
<jsp:include page="index.jsp"></jsp:include>
<p>ENTERED DETAILS ARE :</p>
<p>USER NAME IS : ${param.username}</p>
<p>EMAIL ID IS : ${param.email}</p>
<p>GENDER IS : ${param.gender}</p>
<p>DIVISION IS : ${param.division}</p>
</body>
</html>
param.(property) -> prints out the value which is named at index.jsp
Output: