导入类的问题,怎么也想不明白
kekan 2007-05-01 08:32:22 工作目录为webapps\zz\
自己写的类password.class放在webapps\zz\WEB-INF\classes\zz下面
package zz;
import java.io.*;
public class password
{
private String filePath;
private String password;
public password(String filePath) {
this.filePath = filePath;
}
public String getPassword() {
try {
FileInputStream inputFile = new FileInputStream(filePath);
ObjectInputStream in = new ObjectInputStream(inputFile);
password = (String)in.readObject();
in.close();
inputFile.close();
} catch(Exception e) {
e.printStackTrace();
}
return password;
}
public void setPassword(String password) {
try {
FileOutputStream outputFile = new FileOutputStream(filePath);
ObjectOutputStream out = new ObjectOutputStream(outputFile);
out.writeObject(password);
out.flush();
out.close();
outputFile.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
JSP页面test.jsp放在webapps\zz\pages\11\下
<%@ page contentType="text/html; charset=gb2312" language="java" import="zz.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<%
String password = "111";
out.println(password);
password pass = new password("psd.ini");
//pass.setPassword(password);
%>
<body>
</body>
</html>
为什么运行时就出错,错误如下
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 12 in the jsp file: /pages/11/test.jsp
password cannot be resolved to a type
9: String password = "111";
10: out.println(password);
11:
12: password pass = new password("psd.ini");
13: //pass.setPassword(password);
14: %>
15: <body>
An error occurred at line: 12 in the jsp file: /pages/11/test.jsp
password cannot be resolved to a type
9: String password = "111";
10: out.println(password);
11:
12: password pass = new password("psd.ini");
13: //pass.setPassword(password);
14: %>
15: <body>
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:415)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)