Data Declaration and Method Definition
Data Declaration and Method Definition
-There may arise a case when a programmer requires to use his own method.
-But till yet, we have seen that whatever we write goes in servlet method (service ()).
-But till yet, we have seen that whatever we write goes in servlet method (service ()).
-As JSP Declaration doesn't provide any output they are used in conjuction with JSP Expression and JSP Scriplets.
<%! Data Declaration; %>
<%! Method Definition()
{
}
%>
<%! int count=0; %>
<%! public String m1()
{
return "Hello";
}
%>
-Method returning some values are allowed in JSP Declaration.
http://localhost:8080/learningkattaWebApp/j2?name=Tom
HelloDeclarationJSP.jsp
<html>
<body>
Data Declaration and Method Definition
b) Data Declaration and Method Definition
-There may arise a case when a programmer requires to use his own method.
-But till yet, we have seen that whatever we write goes in servlet method (service ()).
-As JSP Declaration doesn't provide any output they are used in conjuction with JSP Expression and JSP Scriplets.
<%! Data Declaration; %>
<%! Method Definition()
{
}
%>
<%! int count=0; %>
<%! public String m1()
{
return "Hello";
}
%>
-Method returning some values are allowed in JSP Declaration.
http://localhost:8080/learningkattaWebApp/j2?name=Tom
HelloDeclarationJSP.jsp
<%!
public String sayHello(String name)
{
return "Hello" + name;
}
%>
Message:<%= sayHello(request.getParameter("name") %?>
<%!
public String sayHello(String name)
{
return "Hello" + name;
}
%>
Message:<%= sayHello(request.getParameter("name") %?>
</body>
</html>