Sunday, July 9, 2017

10. Write a JSP program to implement all the attributes of page directive tag.

index.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Page Attributes </title>
</head>
<body>
<form action="Directive.jsp">
<h1>Enter the value of n1 and n2: </h1>
Number1: <input type="number" name="n1"/><br/>
Number:2 <input type="number" name="n2"/><br/>
<input type="submit"/>
</form>
</body>
</html>

Directive.jsp

<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page info="composed by DSATM" %>
<%@ page language="java"%>
<%@ page buffer="16kb" %>
<%@ page autoFlush="true" %>
<%@ page isThreadSafe="true" %>
<%@ page errorPage="error.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Page Attributes</title>
</head>
<body bgcolor="orange">
<h2> Usage of Import Attributes </h2>
<h2>Todays Date is: <%=new Date() %></h2>
<h2>To See the use of Error page enter n2 value zero and click submit </h2>
<% int n1=Integer.parseInt(request.getParameter("n1"));
int n2=Integer.parseInt(request.getParameter("n2"));
%>
<h2>Value of n1/n2 ==><%=n1/n2 %></h2>
</body>
</html>

error.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page isErrorPage="true" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Page Attributes</title>
</head>
<body>
<h2>Value of n2 variable of zero (n/0 is infinity)</h2>
<h3> Sorry an exception occured!</h3><br/>
<h3> The exception is: <%= exception%></h3>
</body>
</html>

No comments:

Post a Comment