12:49 pm - Saturday July 22, 2017

Expression in JSP

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

 

Expression in jsp scripting elements are used to Execute values based on input given, and can be used to display data in browser without using implicit object in jsp.
Syntax:

<%= expression comes here %>

 

JSP Files:

 

 

 

 

 

 

ExpressionExample.jsp:

<%@ 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>Insert title here</title>
</head>
<body bgcolor="pink">
<form action="ExpressionExample.jsp"><font color="Purple" size=5>

<h2 align="center">**This Program is to Explain the Expression Tag
in JSP.**</h2>
<font size=4>Enter the NO1: <input type="text" name="no1"></input><br>
<br>
Enter the NO2: <input type="text" name="no2"></input> <br>
<br></br>
<input type="submit" value="submit"></input> <br>
<br></br>

<%
	String no1 = request.getParameter("no1");
	String no2 = request.getParameter("no2");

	int no11 = 0, no12 = 0, no13 = 0;
	if (no1 != null)
		no11 = Integer.parseInt(no1);
	if (no2 != null)
		no12 = Integer.parseInt(no2);
	no13 = no11 + no12;
	String no113 = Integer.toString(no13);
	if (no113.equals("0")) {
	} else {
%>
<h3>The Addition Number is <%=no113%></h3>
<%
	}
%> </font></form>
</body>
</html>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
	xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	<display-name>ExpessionExample</display-name>
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.jsp</welcome-file>
	</welcome-file-list>
</web-app>

OUTPUT:

DOWNLOAD+SOURCECODE

Filed in: Z-AJSP Codes

No comments yet.

Leave a Reply