***在JSP页面中使用Bean的问题*** ( 积分: 20 )

  • 主题发起人 主题发起人 阿bao
  • 开始时间 开始时间

阿bao

Unregistered / Unconfirmed
GUEST, unregistred user!
我编写好了一个opendb.java文件,并且编译通过了生成opendb.class文件
package opendb;
import java.sql.*;
public class opendb
{
String strDBDriver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
private Connection conn=null;
String strDBUrl="jdbc:microsoft:sqlserver://localhost:1433;User=hxy;Password=hxy;DatabaseName=nbsdb";
private Statement stmt=null;
ResultSet rs=null;
//<!--注册数据库驱动程序-->
public opendb()
{
try
{
Class.forName(strDBDriver);
}
//异常处理
catch(java.lang.ClassNotFoundException e)
{
System.err.println(&quot;opendb():&quot;+e.getMessage());
}
…………………………………………………
我在另一个JSP中引用这个CLASS
<%@ page contentType=&quot;text/html;
charset=gb2312&quot;
language=&quot;java&quot;
import=&quot;java.sql.*,java.util.*&quot;%>
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;
&quot;http://www.w3.org/TR/html4/loose.dtd&quot;>
<html>
<head>
<title>登陆验证页面</title>
<jsp:useBean id=&quot;db&quot;
class=&quot;opendb.opendb&quot;/>
<%
String getAadno=new String(request.getParameter(TXT_ADNO));
String getAadpw=new String(request.getParameter(TXT_ADPW));
String sql=&quot;select adno,adpw from adtable where adno='&quot;+getAadno+&quot;' and adpw='&quot;+getAadpw+&quot;'&quot;;
ResultSet rs=db.executeQuery(sql);
if(rs.next())
{
system.out.println(&quot;登陆成功&quot;)
}
else
{
system.out.println(&quot;对不起,您的输入有误,请重新输入&quot;)
}
%>
</head>
<body>
</body>
</html>
而且我也设置好了环境变量的CLASSPATH为CLASS文件所在的目录
为什么我运行这个JSP文件时会显示无法编译:如下显示:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 7 in the jsp file: /website/BgSys/admin_login1.jsp
Generated servlet error:
[javac] Compiling 1 source file
D:/tomcat/work/Standalone/localhost/_/website/BgSys/admin_login1_jsp.java:72: ';' expected
}
^

An error occurred at line: 7 in the jsp file: /website/BgSys/admin_login1.jsp
Generated servlet error:
D:/tomcat/work/Standalone/localhost/_/website/BgSys/admin_login1_jsp.java:76: ';' expected
}
^
2 errors

at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:248)
at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:315)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:328)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:427)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:142)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
*************************
回答送20积分,谢谢
 
我编写好了一个opendb.java文件,并且编译通过了生成opendb.class文件
package opendb;
import java.sql.*;
public class opendb
{
String strDBDriver=&quot;com.microsoft.jdbc.sqlserver.SQLServerDriver&quot;;
private Connection conn=null;
String strDBUrl=&quot;jdbc:microsoft:sqlserver://localhost:1433;User=hxy;Password=hxy;DatabaseName=nbsdb&quot;;
private Statement stmt=null;
ResultSet rs=null;
//<!--注册数据库驱动程序-->
public opendb()
{
try
{
Class.forName(strDBDriver);
}
//异常处理
catch(java.lang.ClassNotFoundException e)
{
System.err.println(&quot;opendb():&quot;+e.getMessage());
}
…………………………………………………
我在另一个JSP中引用这个CLASS
<%@ page contentType=&quot;text/html;
charset=gb2312&quot;
language=&quot;java&quot;
import=&quot;java.sql.*,java.util.*&quot;%>
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;
&quot;http://www.w3.org/TR/html4/loose.dtd&quot;>
<html>
<head>
<title>登陆验证页面</title>
<jsp:useBean id=&quot;db&quot;
class=&quot;opendb.opendb&quot;/>
<%
String getAadno=new String(request.getParameter(TXT_ADNO));
String getAadpw=new String(request.getParameter(TXT_ADPW));
String sql=&quot;select adno,adpw from adtable where adno='&quot;+getAadno+&quot;' and adpw='&quot;+getAadpw+&quot;'&quot;;
ResultSet rs=db.executeQuery(sql);
if(rs.next())
{
system.out.println(&quot;登陆成功&quot;)
}
else
{
system.out.println(&quot;对不起,您的输入有误,请重新输入&quot;)
}
%>
</head>
<body>
</body>
</html>
而且我也设置好了环境变量的CLASSPATH为CLASS文件所在的目录
为什么我运行这个JSP文件时会显示无法编译:如下显示:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 7 in the jsp file: /website/BgSys/admin_login1.jsp
Generated servlet error:
[javac] Compiling 1 source file
D:/tomcat/work/Standalone/localhost/_/website/BgSys/admin_login1_jsp.java:72: ';' expected
}
^

An error occurred at line: 7 in the jsp file: /website/BgSys/admin_login1.jsp
Generated servlet error:
D:/tomcat/work/Standalone/localhost/_/website/BgSys/admin_login1_jsp.java:76: ';' expected
}
^
2 errors

at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:248)
at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:315)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:328)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:427)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:142)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
*************************
回答送20积分,谢谢
 
D:/tomcat/work/Standalone/localhost/_/website/BgSys/admin_login1_jsp.java:72: ';' expected
明显是少;啊。。加几个system.out.print();调试语句调试下
 
哪里少?我怎么觉得没少啊?
 
system.out.println(&quot;登陆成功&quot;)
system.out.println(&quot;对不起,您的输入有误,请重新输入&quot;)
在后面加上;
 
if(rs.next())
{
system.out.println(&quot;登陆成功&quot;)[red];[/red]
}
else
{
system.out.println(&quot;对不起,您的输入有误,请重新输入&quot;)[red];[/red]
}
 
现在还用java bean来做,好土啊,现在都用标签库来做,只用一个标签就可以搞定。
 
后退
顶部