bjsxt Lucene项目的jsp

index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'left.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body bgcolor=f1f1f1 style="border-right:#000000 1px solid">
    <a href="searchForm.jsp" target="main">搜索</a><br>
    <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  </body>
</html>


left.jsp

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'left.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body bgcolor=f1f1f1 style="border-right:#000000 1px solid">
    <a href="searchForm.jsp" target="main">搜索</a><br>
    <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  </body>
</html>


top.jsp

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'top.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body bgcolor="green">
    搜索系统 V 11.0<br>
  </body>
</html>



readme.jsp


<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'readme.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    欢迎使用本系统 <br>
  </body>
</html>


searchForm.jsp

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'searchForm.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  <script type="text/javascript">
  function check(){
  	if(document.forms[0].key.value==""){
  		alert("关键词不能为空");
	  	return false;
  	}
  	return true;
  }
  </script>
  <body>
    <form action="results.jsp" method="get" onSubmit="return check();">
    关键词:<input name=key >
    
    
    <input type=submit value="搜索">
    </form>
    
    
    <br>
  </body>
</html>


result.jsp


<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>

<%@ page import="java.io.IOException"%>
<%@ page import="org.apache.lucene.document.Document"%>
<%@ page import="org.apache.lucene.index.CorruptIndexException"%>
<%@ page import="org.apache.lucene.index.Term"%>
<%@ page import="org.apache.lucene.search.Hits"%>
<%@ page import="org.apache.lucene.search.IndexSearcher"%>
<%@ page import="org.apache.lucene.search.Query"%>
<%@ page import="org.apache.lucene.search.TermQuery"%>
<%@ page import="com.bjsxt.lucene.util.*"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

int start = 0;
try{
start = Integer.parseInt(request.getParameter("start"));
}catch(Exception e){}
int max = 10;
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'results.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
	<link rel="stylesheet" type="text/css" href="styles.css">
	

  </head>
    <script type="text/javascript">
  function check(){
  	if(document.forms[0].key.value==""){
  		alert("关键词不能为空");
	  	return false;
  	}
  	return true;
  }
  </script>
  <body>

<%
	String index = "D:\\share\\0400_Servlet_JSP\\soft\\apache-tomcat-5.5.17\\apache-tomcat-5.5.17\\index_cn";
	IndexSearcher searcher=null;
	searcher = new IndexSearcher(index);
	Query query = new TermQuery(new Term("title",request.getParameter("key")));
	Hits hits = searcher.search(query);
	System.out.println(hits.length());
	if(hits.length()>0){

 %>  
	<form action="results.jsp" method="get" name=searchForm onSubmit="return check()">
    	关键词:<input name=key value="<%=request.getParameter("key") %>">
    	<input name=start value="<%=start%>">
    	<input type=submit value="搜索">
    </form>
  一共找到了<%=hits.length() %>条结果
  <div id=gridData>
  <table border=0 cellpadding="3" cellspacing="1">
	  <tr>
		  <td>序号</td>
		  <td>标题</td>
		  <!-- <td>摘要</td> -->
	  </tr>
  <%
  
	for (int i = start; i < start+max; i++) {
		if(i>=hits.length()){
			break;
		}
		Document doc = hits.doc(i);
		String _title = doc.get("title");
		String _summary = doc.get("summary");
		String _path = doc.get("path");
		//D:\share\0100_J2SE\soft\html_zh_CN\html\zh_CN\api\java\lang\String.html
		//http://127.0.0.1/api/java/lang/String.html

		
		_path = _path.replaceAll("D:\\\\share\\\\0100_J2SE\\\\soft\\\\html_zh_CN\\\\html\\\\zh_CN\\\\","");
		_path = _path.replace('\\','/');
		_path = "http://127.0.0.1/"+_path;
		System.out.println(_path);
		
%>
	  <tr>
		  <td><%=i+1 %></td>
		  <td><a href="<%=_path %>"><%=_title %></a></td>
		  <!-- <td><%=com.bjsxt.lucene.util.DataFilter.getHTML(_summary)%></td> -->
	  </tr>
		 
<%	}
	searcher.close(); 

  %>
  
  
  
    </table>
<a href="javascript:first();">首页</a>
<%if(start-max>=0){ %>
	<a href="javascript:previous();">上一页</a>
<%}else{ %>
	上一页
<%} %>
<%if(start+max<hits.length()){ %>
	<a href="javascript:next();">下一页</a>
<%}else{ %>
	下一页
<%} %>
<a href="javascript:last();">尾页</a>
</div>

<script type="text/javascript">
function first(){
	searchForm.start.value=0;
	searchForm.submit();
}
function previous(){
	searchForm.start.value=<%=start-max%>;
	searchForm.submit();
}
function next(){
	searchForm.start.value=<%=start+max%>;
	searchForm.submit();
}
function last(){
	searchForm.start.value=<%=hits.length()/max*max%>;
	searchForm.submit();
}

</script>
<%}else{ %>

	对不起没找到结果,请重新设定搜索条件<a href=javascript:history.back()>返回</a>

<%} %>
     <br>
  </body>
</html>


styles.css


BODY{
	FONT-SIZE: 9pt; 
	line-height: 150%; 
	margin-top:10px;
	margin-bottom:0px;
	margin-left:10px;
	margin- right:0px;
	scrollbar-face-color: #f6f6f6;
	scrollbar-highlight-color: #ffffff; 
	scrollbar-shadow-color: #cccccc; 
	scrollbar-3dlight-color: #cccccc; 
	scrollbar-arrow-color: #330000; 
	scrollbar-track-color: #f6f6f6; 
	scrollbar-darkshadow-color: #ffffff;
}
input{
	BORDER-TOP-WIDTH: 1px; 
	PADDING-RIGHT: 1px; 
	PADDING-LEFT: 1px; 
	BORDER-LEFT-WIDTH: 1px; 
	FONT-SIZE: 9pt; 
	BORDER-LEFT-COLOR: #cccccc; 
	BORDER-BOTTOM-WIDTH: 1px; 
	BORDER-BOTTOM-COLOR: #cccccc; 
	PADDING-BOTTOM: 1px; 
	BORDER-TOP-COLOR: #cccccc; 
	PADDING-TOP: 1px; 
	BORDER-RIGHT-WIDTH: 1px; 
	BORDER-RIGHT-COLOR: #cccccc; 
	font-family: "????", "Arial", "Helvetica", "sans-serif";
	font-size:12px;
}

a:link { FONT-SIZE: 12px;color:#4020a0;text-decoration:none}
a:visited { FONT-SIZE: 12px;color:#4020a0;text-decoration:none}
a:hover { FONT-SIZE: 12px;color:#FF0000; text-decoration:underline; }

td {
	font-size: 12px;
}


#gridData{
	margin-left:2px;
	margin-top:2px;
	padding-top:5px;
	padding-bottom:5px;
	background-color:#E2F0FE;
	width: 100%;
	align:center;
}
#gridData table {
	background-color:#7C9CCB;
	align:center;
	margin: 5px;
	width: 98%;
}
#gridData table tr{
	font-size: 12px;
	background-color:#F2F8FE;
	
}
#gridData table td{
	font-size: 12px;
	AAAAAbackground-color:#F2F8FE;
	
}

.listtable{
	WIDTH: 95%; 
}
.listtable td{
	border-top: 1px solid #ffffff;
	border-bottom: 1px solid #dddddd;
	
}
.listtabletitle{
	color:"#4020a0";
	font-weight:bold;
	FONT-SIZE: 12px;
}

你可能感兴趣的:(java,apache,html,jsp,Lucene)