JSP连接数据库access遇到问题。十万火急!
代码为:
<%@page contentType= "text/html; charset=gb2312 " %>
<%@page language= "java "%>
<%@page import= "java.io.* "%>
<%@page import= "java.util.* "%>
<%@page import= "java.util.Date* "%>
<%@page import= "java.sql.* "%>
<%@page import= "java.net.* "%>
<%@page import= "java.text.* "%>
<%
//-----------------------------
//留言显示程序lyidex.jsp
//-----------------------------
%>
<%
//判断是否是管理员的IP
String WebmasterIP= "10.0.0.1 ";
boolean IsWebmasterIP=false;
String RemoteAddr=new String();
RemoteAddr=request.getRemoteAddr();
if(RemoteAddr.equals(WebmasterIp))
{
IsWebmasterIP=true;
}
int intPageSize; //一页显示的记录
int intRowCount=5; //记录总数
int intPageCount;//总页数
int intPage;//待显示的页数
String strPage;
int i;
//设置一页显示的记录
int PageSize=5;
//取得待显示页码
strPage=request.getParameter( "page ");
if(strPage==null){
//表明在QueryString中没有page这个参数,此时显示第一页数据
intpage=1;
}
else
{
//将字符串转换成整型
intPage=Integer.parseInt(strPage);
if(intPage <1) intPage=1;
}
//连接数据库
String DBDriver= "sun.jdbc.odbc.JdbcodbcDriver ";
try
{
Class.forName(DBDriver);
}
catch(java.lang.ClassNotFoundException ae);
{
System.err.println( "ae: "+ae.getMessage());
}
String sConnStr= "jdbc:odbc:jspdb ";
Connection conn=null;
conn=DriverManger.getConnection(sConnStr, "sa ", " ");
String strSQl; //SQL语句
strSQL= "SELECT * FROM member WHERE flag=1 order by mydate desc ";
Statement stmt=
conn.creatStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet reslut=null;
try
{
result=stmt.executeQuery(strSQL);
}
catch(SQLException be);
{
System.err.println( "be.executeQuery: "+be.getMessage());
}
result.last();
intRowCount=result.getRow();
//计算总页数
intPageCount=(intRowCount+intPageSize-1)/ intPageSize;
//调整待显示页码
if(intPage> intPageCount) intPage=intPageCount;
%>
<html>
<head>
<title> 留言显示 </title>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<style type= "text/css ">
<!--
.table{ border:lpx #FF6600 solid}
-->
</style>
</head>
<body bgcolor= "#FFFFFF "> <center>
<h4>
<div align= "center "> </div>
<div align= "center "> 留言列表 </div> </h4>
<table border= "1 " cellspacing= "1 " cellpadding= "2 " bordercolor= "#FF6600 " align= "center ">
<tr>
<%
if(IsWebmasterIP){
out.println( " <th> 管理留言 </th> ");
}
%>
<th> <font color= "#FF6600 "> 留言者 </font> </th>
<th> <font color= "#FF6600 "> 留言者登录 </font> </th>
<th> <font color= "#FF6600 "> Email地址 </font> </th>
<th> <font color= "#FF6600 "> 留言内容 </font> </th>
<th> <font color= "#FF6600 "> 留言日期 </font> </th>
</tr>
<%
out.println( " <a href= "http:localhost:8080/jsp/addmsg.jsp "> 新增留言..... </a> <p> \n ");
if(intPageCount> 0){
//将记录指针定位到待显示页的第一条记录
try{
result.absolute((intPage-1)* intPageSize +1);
}
catch(Exception e){
out.println( "error: "+e.getMessage());
}
//显示数据
i=0;
while(i <intPageSize && !result.isAfterLast()){
%>
<tr>
<%
if(IsWebmasterIP){
out.println( " <td> <a href=http://localhost:8080/jsp/erase.jsp?id= "+result.getString(1)+ "> 删除本篇 </a> <td> ");
}
%>
<td> <font color= "#FF6600 "> <%=result.getString(2)%> </font> </td>
<td> <font color= "#FF6600 "> <%=result.getString(3)%> </font> </td>
<td> <font color= "#FF6600 "> <%=result.getString(4)%> </font> </td>
<td> <font color= "#FF6600 "> <%=result.getString(5)%> </font> </td>
<td> <font color= "#FF6600 "> <%=result.getString(6)%> </font> </td>
</tr>
<%
result.next();
i++;
}
}
%>
</table>
<div align= "center "> <br>
<%
//断开数据库
result.close();
conn.close();
%>
第 <%=intPage%> 页 共 <%=intPageCount%> 页
<%if(intPageCount){%>
<a href= "http://localhost:8080/jsp/lyidex.jsp?page= <%=intPage-1%> "> 下一页 </a>
<%}%>
<%if(intPage> 1){%>
<a href= "http://localhost:8080/jsp/lyidex.jsp?page= <%=intPage-1%> "> 上一页 </a>
<%}%> </center>
</div>
</body>
</html>
出错误页面提示为:
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
Generated servlet error:
Syntax error on token "* ", delete this token
An error occurred at line: 14 in the jsp file: /lyidex.jsp
Generated servlet error:
Syntax error on token "; ", delete this token
An error occurred at line: 14 in the jsp file: /lyidex.jsp
Generated servlet error:
Syntax error on token "; ", delete this token
An error occurred at line: 104 in the jsp file: /lyidex.jsp
Generated servlet error:
Syntax error, insert ") " to complete MethodInvocation
An error occurred at line: 104 in the jsp file: /lyidex.jsp
Generated servlet error:
Syntax error, insert "; " to complete Statement
An error occurred at line: 104 in the jsp file: /lyidex.jsp
Generated servlet error:
Syntax error on token "/ ", invalid AssignmentOperator
An error occurred at line: 104 in the jsp file: /lyidex.jsp
Generated servlet error:
Syntax error on token "jsp ", ( expected after this token
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:397)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.
--------------------------------------------
[解决办法]
太长,懒的看,给你个小窍门……
把你jsp页面里出错的代码段贴到servlet里检查有没有语法错误
没有语法错误的话一般不会出现不能编译的异常
[解决办法]
把这个删除试试看吧, <%@page import= "java.util.Date* "%>
我也遇到这样相似的问题
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.myexception.cn/j2ee/2308.html