Use of packages in JSP
How to use of packages in JSP? Given with example...
Explanation
Java classes stored as packages can be effectivley used in JSP. Following is an example to explain the usage of Java Class.
Example: Example1.jsp
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ page import="mypack.Display" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
Display cnt=new Display();
String outpt=cnt.echoVar("Hi da");
out.println(outpt);
%>
Counter.java
package mypack;
public class Display
{
public String echoVar(String var){
return var;
}
}
In the above example we have used a package "Counter" with a class "echovar". In the example we have created a new instance of the package "Counter" to use the class "echovar" to display the text input.