11:04 am - Thursday April 27, 2017

Declaration 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

Declaration in jsp scripting elements are used to declare variables or to define concrete methods, we can’t do any execution inside this jsp declaration
Syntax:

<%! Declaration goes here %>

 

JSP Files:

 

 

 

 

 

 

DeclarationExample.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="DeclarationExample.jsp"><font color="Purple" size=5>

<h2 align="center">**This Program is to Explain the Declaration 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 = add(no11, no12);
	String no113 = Integer.toString(no13);
	if (no113.equals("0")) {
	} else {
%>
<h3>The Addition Number is <%=no113%></h3>
<%
	}
%> <jsp:declaration>public int add(int i, int j) {
		return i + j;
	}</jsp:declaration> </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>DeclarationExample</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