哪位知道的给指点一下,JSP文件操作

zhangleibbq 2003-09-15 02:50:36
我用的服务器是Tomcat4.0,我写了一个Bean功能是生成一个HTML文件,但是我在JSP面页中
调用该Bean的时候HTML不能正常的生成,但是main方法中能正常地生成,哪位帮我看看是什么情况,该Bean的代码如下
package classes;

import java.sql.*;
import javax.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.io.*;
import java.text.NumberFormat;

/**产生拓朴图的类*/
public class TuopuCreater
{
private JspWriter writer;
public TuopuCreater()
{
}
/**产生拓朴图Html文件*/
public void create() throws Exception
{
try{this.writeHtmlHead();
this.getPictureRoot();
this.writeHtmlEnd();
}catch(Exception e){throw e;}
}
/**找到拓朴图的根元素*/
private void getPictureRoot() throws Exception
{
boolean bb=false;
String imagepath = "";
String deptname = "";
String deptid = "";
try{
DataBaseOperator dboperator = new DataBaseOperator();
String sql = "Select ImagePath,DeptName,DeptID From DeptInfo Where RelationDeptID ='无'";
ResultSet rs = dboperator.executeQuery(sql);
while(rs.next())
{
imagepath = rs.getString("ImagePath");
deptname = rs.getString("DeptName");
deptid = rs.getString("DeptID");
bb=true;
}
}catch(Exception e){throw e;}
String str[][] = new String[1][3];
str[0][0] = imagepath;
str[0][1] = deptname;
str[0][2] = deptid;
if(bb==true)
this.nextLevel(str);
System.out.println("Creating root...");
}
/**找到其他元素*/
public void setWriter(JspWriter jw)
{
this.writer = jw;
}
/**将每一个部门写入Html的方法*/
private void writeDepToHtml(String str[][])
{
//将每一层的部门信息写入Html文档
double countDep=str.length;
//规定每个部门占用的宽度
double dd=1/(countDep+2);
//System.out.println("dd的值: "+dd);
NumberFormat nf = NumberFormat.getPercentInstance();
String widthDep=nf.format(dd);
try
{
PrintStream ps=LogWriter.getPrintStream("../../defaultroot/frame/tuopu.jsp",true);
//图片层
ps.println("<tr align=\"center\">");
ps.println("<td align=center width=100%>");
ps.println("<table align=center border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">");
ps.println("<tr align=center>");
ps.println("<td align=center width="+widthDep+"> </td>");
for(int i=0;i<str.length;i++)
{
ps.println("<td width="+widthDep+" align= center ><img src=\""+str[i][0]+"\"></td>");
}
ps.println("<td align=center width="+widthDep+"> </td>");
ps.println("</tr>");
//标识层
ps.println("<tr align=center>");
ps.println("<td align=center width="+widthDep+"> </td>");
for(int i=0;i<str.length;i++)
{
ps.println("<td width="+widthDep+" align= center ><a href=\"frame.jsp\">"+str[i][1]+"</a></td>");
}
ps.println("<td align=center width="+widthDep+"> </td>");
ps.println("</tr>");
ps.println("<tr align=center>");
ps.println("</tr>");
ps.println("</table>");
ps.println("</td>");
ps.println("</tr>");

System.out.println("Write information to html...");
ps.flush();
ps.close();
}
catch(Exception e){System.out.println("ABC"+e.getMessage());}
}
private void writeHtmlHead() throws Exception
{
//System.out.println("正在写入Html文件");
try{
PrintStream ps = LogWriter.getPrintStream("../../defaultroot/frame/tuopu.jsp",false);
if(ps==null)
{
System.out.println("PrintStream null!!!!!");
}
ps.println("<%@page contentType=\"text/html;charset=gb2312\"%>");
ps.println("<html>");
ps.println("<head>");
ps.println("<title>公司拓朴图");
ps.println("</title>");
ps.println("</head>");
ps.println("<body>");
ps.println("<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">");
ps.println("<tr align = center>");
ps.println("<td width = 20 colspan = 22> </td>");
ps.println("</tr>");
ps.flush();
ps.close();
}catch(Exception e){throw e;}

}
private void writeHtmlEnd() throws Exception
{
//System.out.println("正完成Html文件的书写");
try{
PrintStream ps = LogWriter.getPrintStream("../../defaultroot/frame/tuopu.jsp",true);
ps.println("</table>");
ps.println("</body>");
ps.println("</html>");
ps.flush();
ps.close();
}catch(Exception e){throw e;}
}
/**找出图中下一层的方法*/
private void nextLevel(String parent[][])
{
this.writeDepToHtml(parent);
//传进来的时候先将本层的信息写入Html文件
int count = 0;
String subdep[][] = null; //下一层的部门信息
for(int i = 0;i<parent.length;i++)
{
String sql = "Select Count(*) Cou From DeptInfo Where RelationDeptID ='"+parent[i][2]+"'";
try{
DataBaseOperator dboperator = new DataBaseOperator();
ResultSet rs = dboperator.executeQuery(sql);
while(rs.next())
{
count+=rs.getInt("Cou");
}
}catch(Exception e){}
}
//System.out.println("本层有"+count+"个子部门");
if(count==0)
{
return;
}
subdep = new String[count][3];
int j = 0;
for(int i = 0;i<parent.length;i++)
{
String sql = "Select ImagePath,DeptName,DeptID From DeptInfo Where RelationDeptID ='"+parent[i][2].trim()+"'";
try{
DataBaseOperator dboperator = new DataBaseOperator();
ResultSet rs = dboperator.executeQuery(sql);
while(rs.next())
{
subdep[j][0] = rs.getString("ImagePath");
subdep[j][1] = rs.getString("DeptName");
subdep[j][2] = rs.getString("DeptID");
//System.out.println(subdep[j][0]+" "+subdep[j][1]+" "+subdep[j][2]+" ");
j++;
}
}catch(Exception e){System.out.println("AA"+e.getMessage());}
}
this.nextLevel(subdep);
System.out.println("Searching next level...");
//return subdep;
}

public static void main(String args[])
{
try{
TuopuCreater tc = new TuopuCreater();
tc.create();
}catch(Exception e){System.out.println(e.getMessage());}
}

}
...全文
30 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧