在学习时JSP时,有一个制作搜索引擎的例子,学着做了后出现了一个问题,一直解决不了,希望在这里有哪位能够帮忙解答一下,搞了好久了.谢谢!!下面的是用tomcat6.0的,编好后在IE中运行时的报错内容:type Exception reportmessage 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: 43 in the generated java file
Syntax error, insert "}" to complete ClassBodyAn error occurred at line: 265 in the generated java file
Syntax error, insert "else Statement" to complete IfStatementAn error occurred at line: 265 in the generated java file
Syntax error, insert "}" to complete BlockAn error occurred at line: 265 in the generated java file
Syntax error, insert "}" to complete BlockAn error occurred at line: 276 in the generated java file
Syntax error on token "}", delete this tokenStacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:317)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.下面是源代码:<!--这是search.jsp文件-->
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<!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>
<style type="text/css">
<!--
.unnamed1{ font-size: 16px; line-heigh:20px;} 
-->
</style>
</head><body text="#000000">
<br>
<h3>站内搜索结果</h3>
<%! 
String filterweb(String str,char c1,char c2)
{
int pos1=str.indexOf(c1);
int pos2=str.indexOf(c2);
while((pos1!=-1)&&(pos2!=-1))
{
str=str.substring(0,pos1)+str.substring(pos2+1,str.length());
pos1=str.indexOf(c1);
pos2=str.indexOf(c2);
}
return str;
}
%>
<%
String[] FileArray=new String[1000];
int pFileArray=0;
String[] DirectoryStack=new String[1000];
int pDirectoryStack=0;
String findStr;
findStr=request.getParameter("findStr");
if((findStr==null)||(findStr.equals(""))) 
{
out.println("查找关键字不能为空!");return;
}findStr=new String(findStr.getBytes("8859_1"));
findStr=findStr.trim();
String realPath="";
String element="";
String tmps="";
Iterator<String> iter=null;
Collection set;
set=application.getResourcePaths("/");
iter=set.iterator();
while(iter.hasNext())
{
element=iter.next();
realPath=application.getRealPath("/");
realPath=realPath+element.substring(1,element.length());
tmps=realPath.substring(realPath.length()-1,realPath.length());
if(tmps.equals("/"))   //如果为目录
{
realPath=realPath.replace('/','\\');
realPath=realPath.substring(0,realPath.length()-1);
DirectoryStack[pDirectoryStack++]=realPath;   //入队列
}
else
{
if(realPath.lastIndexOf(".htm")!=-1)  //只搜索htm/html文件
{
FileArray[pFileArray++]=realPath;
}
}

}
while(pDirectoryStack!=0)  //如果队列不为空
{
pDirectoryStack--;
String CurPath=DirectoryStack[pDirectoryStack];
String relativePath=application.getRealPath("/");
relativePath="\\"+CurPath.replace(relativePath,""); //获取相对路径
set=application.getResourcePaths(relativePath);
iter=set.iterator();
while(iter.hasNext())
{
element=iter.next();
realPath=application.getRealPath("/");
realPath=realPath+element.substring(1,element.length());
tmps=realPath.substring(realPath.length()-1,realPath.length());
if(tmps.equals("/"))   //如果为目录
{
realPath=realPath.replace('/','\\');
realPath=realPath.substring(0,realPath.length()-1);
DirectoryStack[pDirectoryStack++]=realPath;
}
else
{
realPath=realPath.replace('/','\\');
if(realPath.lastIndexOf(".htm")!=-1)
{
FileArray[pFileArray++]=realPath;
}
}
}
}
//-----------------依次检索站内的每个HTML冈页---------------
int curFileNo=0;
int htmCount=0;
for(curFileNo=0;curFileNo<pFileArray;curFileNo++)
{
realPath=FileArray[curFileNo];
int posw=realPath.lastIndexOf("\\");
String ph=realPath.substring(0,posw+1);
String fn=realPath.substring(posw+1,realPath.length());
File f=new File(ph,fn);
if(f.exists())
{
if(f.isHidden()) continue;

}
FileInputStream fis=null;
fis=new FileInputStream(realPath);
BufferedReader br=new BufferedReader(new InputStreamReader(fis));
String filestring="";
String tempstring="";
while((tempstring=br.readLine())!=null) //把网页文件读入字符串
{
filestring=filestring+tempstring;
}
//---------------------开始过滤无关信息---------------------
int loc1=filestring.indexOf("<title>");
int loc2=filestring.indexOf("</title>");
String title="";
if(loc1!=-1&&loc2!=-1)
{
title=filestring.substring(loc1+7,loc2);
}
int pos1=filestring.indexOf("<body");
int pos2=filestring.indexOf("</body>");
filestring=filestring.substring(pos1,pos2);
filestring=filestring.replace("&nbsp;","");
filestring=filterweb(filestring,'<','>');
filestring=filestring.replace(" ","");
filestring=filestring.replace("  ","");
filestring=filestring.replace("\n","");
String ShowStr="";
int start=-1;
boolean FindOK=false;
if((start=filestring.indexOf(findStr))!=-1)//找正文
{
pos1=start-80;
pos2=start+80;
if(pos1<0) pos1=0;
if(pos2>filestring.length()) pos2=filestring.length();
ShowStr=filestring.substring(pos1,pos2);
ShowStr=ShowStr.replace(findStr,"<b><font color=#ff0000>"+findStr+"</font></b>")+"...";
FindOK=true;
}
if(!FindOK) //如果在正文中找不到,则找标题
{
if(title.indexOf(findStr)!=-1)
{
ShowStr=title.replace(findStr,"<b><font color=#ff0000>"+findStr+"</font></b>");
FindOK=true;

}
}
if(FindOK)
{
htmCount++;
String ROOTPath=application.getRealPath("/");
String relpath=realPath.replace(ROOTPath,"");
String httpstr="http://"+request.getServerName()+":"+request.getServerPort()+"/"+relpath;
httpstr=httpstr.replace("\\","/");
%>
<table width="719" border="0" class="unnamed1">
  <tr>
<td><u><a href="<%= httpstr %>"><%= title %></a></u></td>
  </tr>
  <tr>
<td><%= ShowStr %></td>
  </tr>
</table>
<br>
}
}
out.println("<font color=#00cc00><b>注:总共搜索了站内的<font color=red>"+pFileArray+"</font>个htm/html文件,一共发现<font color=red>"+htmcount+" </font>个文件,包含关键字:<font color=red>"+findstr+"</font>.</b></font></br>");%>
<hr>
<form action="search.jsp" method="post" name="form1">
关键字:
<input type="text" name="findstr">
<input type="submit" name="Submit" value="查询">
</form>
<br>
</body>
</html>

解决方案 »

  1.   

    An error occurred at line: 43 in the generated java file
    Syntax error, insert "}" to complete ClassBodyAn error occurred at line: 265 in the generated java file
    Syntax error, insert "else Statement" to complete IfStatementAn error occurred at line: 265 in the generated java file
    Syntax error, insert "}" to complete BlockAn error occurred at line: 265 in the generated java file
    Syntax error, insert "}" to complete BlockAn error occurred at line: 276 in the generated java file
    Syntax error on token "}", delete this token -- 人家不是给出了错误信息,要自己看,不要遇到问题想都不想就拿来问
      

  2.   

    我也看了提示信息,说43行语法错误,
    if((findStr==null)||(findStr.equals(""))) 

    out.println("查找关键字不能为空!");return; 
    }
    就这一句,但也没看出来呀? 
      

  3.   


    这个是在你的jsp页面对应的 java文件里 -- tomcat 的work目录下