javaBean连接SQL Server 2000数据库
(1)我把msbase.jar mssqlserver.jar三个文件放在WEB-INF\的lib文件下请问以下是怎么回事?
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /ch9/jsp_javabean/addMessage.jsp(2,0) The value for the useBean class attribute com.jspdev.ch9.MessageVO is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:150)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1227)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Generator.generate(Generator.java:3272)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:244)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
(2)我是用的Tomcat5.0+jdk1.4+sql server 2000我的操作目录是C:\Tomcat 5.0\webapps\ROOT(Tomcat的安装目录) lib下有msbase.jar mssqlserver.jar msutil.jar 三个目录 以下是我在光盘中的程序,请问以下程序怎样才能正常编译?
package com.jspdev.ch9;
import com.microsoft.jdbc.sqlserver.SQLServerDriver;
import java.sql.*;
import java.util.*;
public class MessageBean
{
private Connection con;
MessageVo msg;
public MessageBean()
{
String CLASSFORNAME= "com.microsoft.jdbc.sqlserver.SQLServerDriver ";
String SERVANDDB= "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=jspdev ";
String USER= "bn ";
String PWD= "bn ";
try
{
Class.forName(CLASSFORNAME);
con=DriverManager.getConnection(SERVANDDB,USER,PWD);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void setMessage(MessageVo msg)
{
this.msg=msg;
}
public void addMessage()throws Exception
{
try
{
PreparedStatement stm=con.prepareStatement( "insert into message values(?,?,?,?,?) ");
stm.setString(1,msg.getTitle());
stm.setString(2,msg.getName());
stm.setDate(3,new java.sql.Date(new java.util.Date().getTime()));
if((msg.getEmail()).length()==0)
stm.setString(5,null);
else stm.setString(5,msg.getEmail());
stm.setString(4,msg.getContent());
try
{
stm.executeQuery();
}
catch(Exception e)
{ }
con.close();
}
catch(Exception e)
{
e.printStackTrace();
throw e;
}
}
public Collection getMessage() throws Exception
{
Collection ret=new ArrayList();
try
{
Statement stm=con.createStatement();
ResultSet result=stm.executeQuery( "select count() from message ");
int message_count=0;
if(result.next())
{
message_count=result.getInt(1);
result.close();
}
if(message_count> 0)
{
result=stm.executeQuery( "select * from message order by time desc ");
while(result.next())
{
String title=result.getString( "title ");
String name=result.getString( "name ");
String mail=result.getString( "mail ");
String content=result.getString( "content ");
java.sql.Date date=result.getDate( "time ");
MessageVo message=new MessageVo();
message.setName(name);
message.setTitle(title);
message.setContent(content);
message.setDate(date);
message.setEmail(mail);
ret.add(message);
}
result.close();
stm.close();
}
con.close();
}
catch(Exception e)
{
e.printStackTrace();
throw e;
}
return ret;
}
}
[解决办法]
报告的错误是由下面这句引起的:
package com.jspdev.ch9;
意思是说 Tomcat 不认识 jspdev.ch9 , 可能你的光盘上有一个 jspdev.jar 的文件, 也需要把它放在 WEB-INF\lib 目录里 . 我想这个应该在书上或者光盘中有详细的说明 .
[解决办法]
查看一下有沒有com.jspdev.ch9包,MessageVO是不是在這個包下面
[解决办法]
org.apache.jasper.JasperException: /ch9/jsp_javabean/addMessage.jsp(2,0) The value for the useBean class attribute com.jspdev.ch9.MessageVO is invalid.
查查addMessage.jsp的第二行,这里报错,看你的jsp代码是什么?
[解决办法]
学习一下....
[解决办法]
帮你顶
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html