Implementing a resource-like Explorer-type file and directory collapse with JSP (code example)
Last Update:2017-02-28
Source: Internet
Author: User
js| Example <%@ page import = "SqlData"%>
<%@ page import= "java.sql.*"%>
<%@ page contenttype= "text/html;charset=gb2312"%>
<jsp:usebean id= "Sqlbean" class= "SqlData" scope= "session"/>
<html>
<body background= ". /images/back.jpg ">
<p align= "center" ><font size= "6" face= "italics _gb2312" > Introduction to Mao Zedong Thought </font></p>
<%
String aa,bb,cc,dd,ee,ff;
ResultSet rs=sqlbean.executequery ("SELECT * from Maogai");
int i=1,j=0;
while (Rs.next ())
{
aa=rs.getstring ("Sectiontype");
bb=rs.getstring ("sectionname");
cc=rs.getstring ("Indexfile");
ee=rs.getstring ("ZipFile");
Ff=rs.getstring ("Onlinefile");
dd=rs.getstring ("SESSIONID");
if (aa.indexof (' chap ') >-1)
{
if (j==1)
{
i=i+1;
out.println ("</table></div>");
}
j=0;
out.println ("");
out.println ("<div align= ' center ' >");
out.println ("<center>");
out.println ("<table border= ' 0 ' width= ' 90% ' height= ' 0 ' cellspacing= ' 0 ' cellpadding= ' 0 ' >");
out.println ("<tr>");
out.println ("<td height= ' 0 ' ><img name= ' img" +string.valueof (i) + "' border= ' 0 ' src= '". /images/fclosed.gif ' onclick= ' showandhide (div "+string.valueof" (i) + "," + "img" +string.valueof (i) + ") ' >");
out.print (bb+ "</td></tr></table></center></div>");
}
Else
{
if (j==0)
{
j=1;
out.println ("<div style= ' Display:none ' Id=div" +string.valueof (i) + "align= ' center ' >");
out.println ("<center>");
out.println ("<table border= ' 0 ' width= ' 90% ' height= ' 0 ' cellspacing= ' 0 ' cellpadding= ' 0 ' >");
out.println ("<tr><td height= ' > <img border= ' 0 ' src= ')." /images/file.gif ' > ');
out.print ("<a href=" windowsopen.jsp?indexfile=maogai/"+cc+" &sessionid= "+dd+" &zipfile= "+ee+" & onlinefile= "+ff+" ">" +bb+ "</a></td></tr>");
}
Else
{
out.println ("<tr><td height= ' > <img border= ' 0 ' src= ')." /images/file.gif ' > ');
Out.print ("<a href= ' windowsopen.jsp?indexfile=maogai/" +cc+ "&sessionid=" +dd+ "&zipfile=" +ee+ "& onlinefile= "+ff+" ">" +bb+ "</a></td></tr>");
}
}
}
%>
</body>
</html>
<script language=javascript>
function Showandhide (divname,imgname)
{
if (Divname.style.display = = "Block")
{
Divname.style.display = "None";
imgname.src= ". /images/fclosed.gif ";
Self.focus ();
}
Else
{
divname.style.display = "block";
imgname.src= ". /images/fopen.gif ";
Self.focus ();
}
}
</script>