主题:  在SERVLET中引用文件名变量的错误。

真jkl

职务:普通成员
等级:1
金币:0.0
发贴:62
注册:2001/7/5 11:26:27
#12001/7/11 15:42:11
出现500错误是怎么回事?
这是源代码!

package jTemplet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class JTemplet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";

/**Initialize global variables*/
public void init() throws ServletException {
}
/**Process the HTTP Get request*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("");
out.println("...");
out.println("");
out.println( this.string1() );
out.println("");

}
/**Clean up resources*/
public void destroy() {
}

public static String string1 () throws IOException
{
String strFileName; //文件名
File objFile; //文件对象
FileReader objFileReader; //读文件对象
char[] chrBuffer = new char[1024]; //缓冲
int intLength; //实际读出的字符数(一个中文为一个字符)
String strAll;

//设置待读文件名
strFileName = "/www/htdocs/a.t.htm";
strAll = "";



//创建文件对象
objFile = new java.io.File(strFileName);

//判断文件是否存在
if(objFile.exists())
{//文件存在
//创建读文件对象
objFileReader = new java.io.FileReader(objFile);

//读文件内容
while((intLength=objFileReader.read(chrBuffer))!=-1){
//输出
//out.write(chrBuffer,0,intLength);

strAll = strAll + (new String(chrBuffer)).toString();
chrBuffer = new char[1024];
}


strAll=strAll.trim();

//关闭读文件对象
objFileReader.close();

}
else{//文件不存在
return "下列文件不存在:"+strFileName;
}


return strAll;

}

}