运行jsp页面,出现以下错误。很急,搞了两天,真的是没办法了!!!希望有大神可以看一下!!!
jar包我是这样的,不知道jar包应该放在web—INF下面的lib还是另建一个?我这里另建了一个,都试了试。应该不存在重复问题。
然后报错有一行,应该代码有问题,然后去找
org.apache.jsp.result_jsp._jspService(result_jsp.java:91)
![](https://i-blog.csdnimg.cn/blog_migrate/2e3e2b2a37f748cd55c8b55ff0dfdc9d.png)
91行应该没错吧 还是下面if代码有错??没搞懂
下面贴源码
result.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="servlet.Docs" %>
<%
String query=(String)request.getAttribute("query");
List<Docs> list = new ArrayList<Docs>();
list=(List<Docs>)request.getAttribute("docList");
int totalDocs=(Integer)request.getAttribute("totalDocs");
double time=Double.parseDouble(request.getAttribute("time").toString());
int pageNow=(Integer)request.getAttribute("pageNow");
int pageCount=(Integer)request.getAttribute("pageCount");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="css/main.css">
<title>搜索结果</title>
<script type="text/javascript">
window.οnlοad=function(){
document.getElementById("query").value ="<%=query%>";
}
</script>
</head>
<body>
<div class="nav">
<div class="nav_left">
<a href="index.jsp"><img alt="logo" src="img/LOGO.png"></a>
</div>
<div class="nav_right">
<div class="nav_form">
<form action="search" method="get">
<input id="query" type="text" name="query" value="<%=query%>">
<input type="submit" value=" 搜 索 "><br />
</form>
</div>
</div>
</div>
<div class="docsMain">
<h4>
共搜到<span class="docsNum"><%=totalDocs%></span>个结果|用时<span
class="newsnum"><%=time%></span>秒
</h4>
<%
if (list.size() > 0) {
Iterator<Docs> iter = list.iterator();
Docs docs;
while (iter.hasNext()) {
docs = iter.next();
%>
<h4>
<a href="<%=docs.getLink()%> " target="_blank"><%=docs.getTitle()%></a>
</h4>
<p>
<%=docs.getContent().length() > 300 ? docs.getContent().substring(0, 300) : docs.getContent()%>
</p>
<p><a href="<%=docs.getLink()%>" target="_blank"><%=docs.getLink()%></a></p>
<p>----------------------------------------------------------</p>
</div>
<%
}
}
%>
</div>
<div class="paging">
<ul>
<li><a href="search?query=<%=query%>&&pageNow=1">首页</a></li>
<%
if (pageNow !=1){
%>
<li><a href="search?query=<%=query%>&&pageNow=<%=pageNow - 1%>">上一页</a></li>
<%
}
%>
<%
for (int i = 1; i <= pageCount; i++) {
%>
<li><a href="search?query=<%=query%>&&pageNow=<%=i%>"><%=i%></a></li>
<%
}
%>
<%
if (pageNow != pageCount){
%>
<li><a href="search?query=<%=query%>&&pageNow=<%=pageNow+1%>">下一页</a></li>
<li><a href="search?query=<%=query%>&&pageNow=<%=pageCount%>">末页</a></li>
<%
}
%>
</ul>
<hr>
</div>
<div class="footerinfo">
<p> </p>
</div>
</body>
</html>
SearchServlet .java
public class SearchServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static int totalDocs=0;
private static final int PAGE_SIZE=10;
private int pageCount=1;
private int rowCount=1;
private int pageNow=1;
private static String searchpath="F:\\index";
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
String query=request.getParameter("query");
System.out.println("查询 " + query);
long starTime=System.currentTimeMillis();
if(!"".equals(query)&&query!=null){
ArrayList<Docs> docList=getSearch(query);
String temp_pageNow=request.getParameter("pagNow");
if(temp_pageNow!=null){
pageNow=Integer.parseInt(temp_pageNow);
}
rowCount=totalDocs;
pageCount=(rowCount-1)/PAGE_SIZE+1;
List<Docs> pagelist=docList.subList(PAGE_SIZE*(pageNow-1), PAGE_SIZE*pageNow<rowCount?PAGE_SIZE*pageNow:rowCount);
if(docList.size()!=0){
request.setAttribute("query", query);
request.setAttribute("docList", pagelist);
request.setAttribute("totalDocs", totalDocs);
long endTime=System.currentTimeMillis();
long Time = endTime-starTime;
request.setAttribute("time",(double)Time/1000);
request.setAttribute("pageNow", pageNow);
request.setAttribute("pageCount", pageCount);
//request.setAttribute("highlighter", highlighter);
request.getRequestDispatcher("result.jsp").forward(request, response);
}else {
request.getRequestDispatcher("error.jsp").forward(request, response);
}
}
}
private static ArrayList<Docs> getSearch(String keyword){
ArrayList<Docs> docList=new ArrayList<Docs>();
DirectoryReader directoryReader=null;
try {
Directory directory=FSDirectory.open(new File(searchpath));
directoryReader=DirectoryReader.open(directory);
IndexSearcher indexSearcher=new IndexSearcher(directoryReader);
Analyzer analyzer=new IKAnalyzer();
QueryParser queryParser=new QueryParser(Version.LUCENE_46, "content",analyzer );
Query query=queryParser.parse(keyword);
TopDocs topDocs=indexSearcher.search(query, 500);
totalDocs=topDocs.totalHits;
System.out.println("查找到的文档共有:" + totalDocs);
ScoreDoc[] scoreDocs=topDocs.scoreDocs;
for(int i=0;i<topDocs.scoreDocs.length;i++){
Document document=indexSearcher.doc(scoreDocs[i].doc);
System.out.println("[" + i + "]" + document.get("title"));
System.out.println(document.get("link"));
System.out.println("score:" + scoreDocs[i].score);
Docs docs = new Docs(document.get("title"), document.get("link"),
document.get("content"), totalDocs);
docList.add(docs);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return docList;
}
protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
doPost(request, response);
}
//测试
public static void main(String[] args) {
ArrayList<Docs> docList=new ArrayList<Docs>();
docList=(ArrayList<Docs>)getSearch("帮助");
}
测试有结果,但jsp就是打不开,还是数据没传入jsp??