Showing posts with label classes in jsp. Show all posts
Showing posts with label classes in jsp. Show all posts

Saturday, 17 December 2011

JSP Examples Tutorial - Using Superclass Variables With Subclassed Objects


<HTML>
    <HEAD>
        <TITLE>Using Superclass Variables With Subclassed Objects</TITLE>
    </HEAD>
    <BODY>
        <H1>Using Superclass Variables With Subclassed Objects</H1>
        <%!
            javax.servlet.jsp.JspWriter localOut;
            class BaseClass
            {
                public void start() throws java.io.IOException 
                {
                    localOut.println("Starting...<BR>");
                }
            }
            class DerivedClass1 extends BaseClass
            {
                public void fly() throws java.io.IOException 
                {
                    localOut.println("Flying...<BR>");
                }
            }
            class DerivedClass2 extends DerivedClass1
            {
                public void fly() throws java.io.IOException 
                {
                    localOut.println("Flying...<BR>");
                }
            }
        %>     
        <%
            localOut = out;     
            out.println();
            out.println("Creating a DerivedClass2 object...<BR>");
            BaseClass p = new DerivedClass2();
            p.start();
        %>
    </BODY>
</HTML>

JSP Examples Tutorial - Using Parameterized Constructors


<HTML>
    <HEAD>
        <TITLE>Using Parameterized Constructors</TITLE>
    </HEAD>
    <BODY>
        <H1>Using Parameterized Constructors</H1>
        <%!
            javax.servlet.jsp.JspWriter localOut;
            class a
            {
                a() throws java.io.IOException 
                {
                    localOut.println("In a\"s constructor...<BR>");
                }
            }
            class b extends a  
            {
                b(String s) throws java.io.IOException 
                {
                    localOut.println("In b\"s String constructor...<BR>");
                    localOut.println(s);
                }
            }
        %>     
        <%
            localOut = out;     
            b obj = new b("Hello from JSP!<BR>");
        %>
    </BODY>
</HTML>

JSP Examples Tutorial - Using Inheritance in JSP


<HTML>
    <HEAD>
        <TITLE>Using Inheritance</TITLE>
    </HEAD>
    <BODY>
        <H1>Using Inheritance</H1>
        <%!
            javax.servlet.jsp.JspWriter localOut;
            class BaseClass
            {
                public void start()  throws java.io.IOException
                {
                    localOut.println("Starting...<BR>");
                }
            }
            class DerivedClass extends BaseClass
            {
                public void drive() throws java.io.IOException 
                {
                    localOut.println("Deriving...<BR>");
                }
            }
        %>     
        <%
            localOut = out;     
            out.println("Creating an DerivedClass...<BR>");
            DerivedClass a = new DerivedClass();
            a.start();
            a.drive();
        %>
    </BODY>
</HTML>

JSP Examples Tutorial - Using Abstract Classes in JSP


<HTML>
    <HEAD>
        <TITLE>Using Abstract Classes</TITLE>
    </HEAD>
    <BODY>
        <H1>Using Abstract Classes</H1>
        <%!
            javax.servlet.jsp.JspWriter localOut;
            abstract class a
            {
                abstract String getText() throws java.io.IOException;
                public void printem() throws java.io.IOException 
                {
                    localOut.println(getText());
                }
            }
            class b extends a
            {
                String getText() throws java.io.IOException 
                {
                    return "Hello from JSP!";
                }
            }
        %>     
        <%
            localOut = out;     
            b bObject = new b();
            bObject.printem();
        %>
    </BODY>
</HTML>