Saturday 14 March 2015

jsp:include action


A JSP page invoked by a <jsp:include> action has access to all the implicit objects available to the calling JSP.

Syntax
<jsp:include page="resourcename" flush="true" />
common.jsp
<%!
    final double PI = 3.14;
    
    double getArea(int r){
        return PI*r*r;
    }
%>

<%
    int r = Integer.parseInt(request.getParameter("radius"));
%>

<h1>Area of circle is : 
    <%= getArea(r)%>
</h1>


circle.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Area Of Circle</title>
    </head>
    <body>
        <jsp:include page="common.jsp" flush="true" />
    </body>
</html>


index.html
<!DOCTYPE html>

<html>
    <head>
        <title>Area Of Circle</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <form method="get" action="circle.jsp">
            Enter radius <input type="text" name="radius" required="required"/><br />
            <input type="submit" />
        </form>
    </body>
</html>


Output






Prevoius                                                 Next                                                 Home

No comments:

Post a Comment