请教 class的问题

iwantin 2004-09-21 01:58:35
我自己写了一个class,然后在jsp中调用,结果报错,错误如下:

Generated servlet error:
bad class file: D:\Tomcat\shared\classes\shecasafeapi\ReadConfInfo.class
class file contains wrong class: ReadConfInfo
Please remove or make sure it appears in the correct subdirectory of the classpath.


我得class的内容如下:

import java.io.*;
public class ReadConfInfo
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}

private String filePath;
private BufferedReader file;
public void setFilePath(String Path)
{
filePath = filePath;
}

public String getValue(String strTitle)
{
String strLine;
String strValue = null;
String strTmp;
char FirstChar;
int nIndex;
try
{
file = new BufferedReader(new FileReader(filePath));
}
catch (IOException e)
{
System.out.println("读文件错误");
return null;
}

try
{
while( (strLine = (file.readLine()).trim() )!=null)
{
if ((strLine.length()) != 0)
{

FirstChar = strLine.charAt(0);
if ( (FirstChar != '`') && (FirstChar != '#') && (FirstChar != '['))
{
strTmp = strTitle;
nIndex = strLine.indexOf(strTmp);

}
}
}
}
catch(IOException e)
{
return null;
}

return strValue;


}

}
...全文
122 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
iwantin 2004-09-21
  • 打赏
  • 举报
回复
我把class 放在了shecasafeapi下面,然后,调用的页面如下:

<%@ page import="shecasafeapi.*" %>
<%@ page import="java.util.*"%>
<%@ page contentType="text/html; charset=gb2312"%>

<%

shecasafeapi.ReadConfInfo rf = new shecasafeapi.ReadConfInfo();


%>

错误如下:

D:\Tomcat\work\Catalina\localhost\_\org\apache\jsp\test\testfile_jsp.java:50: cannot access shecasafeapi.ReadConfInfo



An error occurred at line: 5 in the jsp file: /test/testfile.jsp

Generated servlet error:
bad class file: D:\Tomcat\shared\classes\shecasafeapi\ReadConfInfo.class
class file contains wrong class: ReadConfInfo
Please remove or make sure it appears in the correct subdirectory of the classpath.
shecasafeapi.ReadConfInfo rf = new shecasafeapi.ReadConfInfo();
stonecsdn 2004-09-21
  • 打赏
  • 举报
回复
ReadConfInfo没有包名,应该放在\shared\classes\下面或者web-inf/classes下面,不过最好有一个包名,这样就可以建立对应的目录

81,122

社区成员

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

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