The <jsp:include> tag provides you facility to import content
onto one of your JSP, but the content needs to reside within your web
application. The import directive is used at compilation time and its concept
is similar to the Java import class directive. The collection of multiple
classes together organized in a hierarchy is referred to as a package.
Example:
JSP File (import.jsp)
<%@ page import="java.io.*" %>
<!DOCTYPE html>
<html>
<head>
<title>nirajanghimireyworkshop.blogspot.com</title>
<meta charset="UTF-8"/>
</head>
<body>
<h1>JSP import</h1>
Click to open/download file
<%
String file = application.getRealPath("/");
File f = new File(file);
String [] fileNames = f.list();
File [] fileObjects= f.listFiles();
%>
<ul>
<%
for (int i = 0; i <fileObjects.length; i++) {
if(!fileObjects[i].isDirectory()){
%>
<li>
<a href="<%= fileNames[i] %>"><%= fileNames[i] %></a>
(<%= Long.toString(fileObjects[i].length()) %> bytes long)
<%
}
}
%>
</ul>
</body>
</html>
No comments:
Post a Comment