日期:2014-05-18  浏览次数:20816 次

使用JAVABEAN报错,求救
环境JDK+TOMCAT+SQLSERVER   2000
问题:JSP文件调用JAVABEAN错误(JAVABEAN能够正确编译并能够正确生成CLASS文件)
存放位子:文件夹/WEB-INF/CLASSES/下
JAVABEAN文件:
package   forjavabean;
import   java.sql.Connection;
import   java.sql.DriverManager;


public   class   Javabean   {
public   static   Connection   getConnection(){
String   url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=myjob ";
String   user= "sa ";
String   password= " ";
Connection   conn=null;
try{
  conn=   DriverManager.getConnection(url,user,password);
}catch   (Exception   e)   {

}
return   conn;
}
public   Javabean(){
}
}
JSP文件:
  <%@   page   contentType= "text/html;charset=GB2312 "   %>
<%@   page   import= "java.sql.* "   %>
<%request.setCharacterEncoding( "GBK ");%>
<jsp:useBean   id= "forjavabean "   class= "forjavabean.javabean "   scope= "page "/>
<HTML>
<BODY>
<p>
<%
response.setCharacterEncoding( "GBK ");
String   name=request.getParameter( "name ");
String   pass=request.getParameter( "password ");
String   verify= "select   *   from   user1   where   name= ' "+name+ " 'and   pass= ' "+pass+ " ' ";
rs=stmt.executeQuery(verify);
if(rs.next()){            
response.sendRedirect( "itlife.jsp ");}
else{            
response.sendRedirect( "error.jsp ");}    
rs.close();          
stmt.close();          
conn.close();  
%>
</p>
</BODY>
</HTML>
运行JSP文件报错:
org.apache.jasper.JasperException:   /11.jsp(4,0)   The   value   for   the   useBean   class   attribute   forjavabean.javabean   is   invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1200)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1155)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2336)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2386)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2392)
org.apache.jasper.compiler.Node$Root.accept(Node.java:489)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2336)
org.apache.jasper.compiler.Generator.generate(Generator.java:3394)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:210)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:306)
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