360首页检索小说效果如下:
个人完成编写的schoolnet校园网主页如下
在小说模块中,包括:小说类别编号:a、校园爱情 b、动漫同人 c、校园魔法 d、轻小说 e、校园励志 f、校园修真 g、名人传记 h、古典小说 i、 国外小说。小说状态:a、连载中 b、已完结。用户可以阅读完整小说、添加小说进入书架、查看目录、投推荐票(限制只能投一次),用户有权管理自己的书架。
页面效果如下:
1、
2、
3、
4、
5、
数据库相关表设计:
xiaoshuo小说表:包含主键id、小说类别编号typeid、小说状态state、小说标题title、小说文档docu、小说推荐率recommend、点击次数click、小说描述content、更新时间creTime、小说封面photo等。
xiaoshuotype小说分类表:包含主键id、类别名称name。
bookrack书架表:包含主键id、用户userid、小说xiaoshuoid。
votereco小说推荐投票表:包含主键id、用户userid、小说xiaoshuoid
1、小说主页面html代码
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!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="X-UA-Compatible" content="IE=edge, chrome=1" />
<meta name="renderer" content="webkit" />
<meta name="Keywords" content="个人主页、说说、相册、好友、日志、音乐、新闻、新鲜事" />
<meta name="Description"
content="超酷的校园网、校园交友平台,创新的校园资源获取与分、专注打造最好的校园真实社交网络!" />
<title>校园小说页面_校园网</title>
</head>
<body>
<div id="wrapper">
<jsp:include page="../public/head.jsp" />
<div id="page_main" class="clearfix">
<div class="page-right">
<div class="site-nav">
<span>当前位置 : </span><a href="/schoolnet/login.do?flag=goIndexUI">首页</a>
>> <a href="/schoolnet/login.do?flag=goHomeUI" title="">个人主页</a>>>小说
</div>
<div class="page-news">
<div class="content">
<div class="mes_response" id="mes_response">
<table>
<tr>
<th class="news-time">小说</th>
</tr>
<tr>
<td><p>按类型:</p>
<div id="clearClass" class="pages" style="margin-top:-10px">
<a class="current" href="javascript:void(0)"
onclick="setXiaoshuotype(this)" name="all" title="1">全部
</a>
<c:forEach var="xiaoshuotype" items="${xiaoshuotypes }">
<a href="javascript:void(0)" onclick="setXiaoshuotype(this)"
name="${xiaoshuotype.id }" title="1">${xiaoshuotype.name
}</a>
</c:forEach>
</div>
<tr>
<td><br />
<p>按更新:</p>
<div id="clearClass2" class="pages">
<a href="javascript:void(0)"
onclick="setXiaoshuotype3(this)" name="all" title="1"
class="current">全部</a> <a href="javascript:void(0)"
onclick="setXiaoshuotype3(this)" name="lianzai" title="1">
连载中</a> <a href="javascript:void(0)"
onclick="setXiaoshuotype3(this)" name="wanjie" title="1">
已完结</a>
</div></td>
</tr>
<tr>
<td>
<div id="showxiaoshuos">
<div id="ajaxpage" class="pages" style="width:100%">
<a href="javascript:void(0)"
onclick="setXiaoshuotype2(this)" name="all" title="1"
class="current"> 首页 </a> <a href="javascript:void(0)"
onclick="setXiaoshuotype2(this)" name="all"
title="${pageNow-1 }" class="current"> 上一页 </a> <a
href="javascript:void(0)"
onclick="setXiaoshuotype2(this)" name="all"
title="${pageNow+1 }" class="current"> 下一页 </a> <a
href="javascript:void(0)"
onclick="setXiaoshuotype2(this)" name="all"
title="${PageCount }" class="current"> 尾页 </a> <a
class="current2">第${pageNow }页</a><a class="current2">共${PageCount
}页</a><a class="current2">${allrows }部小说</a>
</div>
</br>
<c:forEach var="xiaoshuo" items="${xiaoshuos }">
<div class="xiaoshuos">
<a
href="/schoolnet/xiaoshuo.do?flag=goxiaoshuodescript&pageNow=1&id=${xiaoshuo.id }"
title="${xiaoshuo.title }"> <img
src="/schoolnet/Media/txt/photo/${xiaoshuo.photo }"
width="104px" height="150px">
</a>
<p class="ellipsis">
<a
href="/schoolnet/xiaoshuo.do?flag=goxiaoshuodescript&pageNow=1&id=${xiaoshuo.id }"
title="${xiaoshuo.title }">${xiaoshuo.title }</a>
</p>
</div>
</c:forEach>
</div></td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
<jsp:include page="../public/foot.jsp" />
</div>
</body>
</html>
2、小说详情页面html代码
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!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="X-UA-Compatible" content="IE=edge, chrome=1" />
<meta name="renderer" content="webkit" />
<meta name="Keywords" content="个人主页、说说、相册、好友、日志、音乐、新闻、新鲜事" />
<meta name="Description"
content="超酷的校园网、校园交友平台,创新的校园资源获取与分、专注打造最好的校园真实社交网络!" />
<title>校园小说页面_校园网</title>
</head>
<body>
<div id="wrapper">
<jsp:include page="../public/head.jsp" />
<div id="page_main" class="clearfix">
<div class="page-right">
<div class="site-nav">
<span>当前位置 : </span><a href="/schoolnet/login.do?flag=goIndexUI">首页</a>
<a href="/schoolnet/login.do?flag=goHomeUI" title="">个人主页</a>小说
</div>
<div class="page-news">
<div class="content">
<div class="mes_response" id="mes_response">
<table>
<tr>
<th class="news-time">小说</th>
</tr>
<tr>
<td>
<div>
<div style="float:left">
<a href="/schoolnet/xiaoshuo.do?flag=goxiaoshuodescript&pageNow=1&id=${xiaoshuo.id }"
title="${xiaoshuo.title }"> <img src="/schoolnet/Media/txt/photo/${xiaoshuo.photo }"
width="104px" height="150px"> <br />${xiaoshuo.title }</a>
</div>
<div style="float:left;padding-left:20px">
<div style="float:left;">
<p>类型 : ${xiaoshuo.xiaoshuotype.name }</p>
<p> 状态 :
<c:if test="${xiaoshuo.state==1 }">连载中</c:if>
<c:if test="${xiaoshuo.state==2 }">已完结</c:if>
</p>
<p>更新 : ${xiaoshuo.creTime }</p>
<p>
<span class="pages"> <a class="current" href="javascript:void(0)"
onclick="javascript:window.history.go(-1)">返回</a> </span>
</p>
</div>
<div style="float:left;padding-left:20px">
<p>点击次数 : ${xiaoshuo.click }</p>
<p>推荐率 : ${fn:length(userxiaoshuoreco) }</p>
<p>章数 : ${count }章</p>
<p>文档 : txt</p>
</div>
</div>
</div></td>
</tr>
<tr>
<td><input id="xiaoshuoid" value="${xiaoshuo.id }"
type="hidden"> <input id="userid"
value="${loginuser.id }" type="hidden">
<div class="pages">
<a class="current" href="/schoolnet/xiaoshuo.do?flag=goxiaoshuodisplay&pageNow=1&id=${xiaoshuo.id }">点击阅读</a>
<a class="current" href="/schoolnet/xiaoshuo.do?flag=goxiaoshuoshowUI&pageNow=1&id=${xiaoshuo.id }"
title="${xiaoshuo.title }">查看目录</a>
<c:if test="${userxiaoshuo==null }">
<span id="setbooks"><a href="javascript:void(0);"
onclick="setBooks()" title="加入书架" class="current"
style="background:#1093d7;">加入书架</a>
</span>
</c:if>
<c:if test="${userxiaoshuo!=null }">
<a title="已在书架" class="current" style="background:#999;">已在书架</a>
</c:if>
<a href="/schoolnet/xiaoshuo.do?flag=gomyxiaoshuoUI&pageNow=1"
class="current">我的书架</a>
<c:if test="${userxiaoshuoreco==null }">
<span id="setreco"><a href="javascript:void(0);"
class="current" onclick="setreco()">投推荐票</a>
</span>
</c:if>
<c:if test="${userxiaoshuoreco!=null }">
<a title="已推荐" class="current" style="background:#999;">已推荐</a>
</c:if>
</div>
<p>描述:</p>
<p>${xiaoshuo.content }</p>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
<jsp:include page="../public/foot.jsp" />
</div>
</body>
</html>
3、小说章数目录页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!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="X-UA-Compatible" content="IE=edge, chrome=1" />
<meta name="renderer" content="webkit" />
<meta name="Keywords" content="个人主页、说说、相册、好友、日志、音乐、新闻、新鲜事" />
<meta name="Description"
content="超酷的校园网、校园交友平台,创新的校园资源获取与分、专注打造最好的校园真实社交网络!" />
<title>校园小说页面_校园网</title>
</head>
<body>
<div id="wrapper">
<jsp:include page="../public/head.jsp" />
<div id="page_main" class="clearfix">
<div class="page-right">
<div class="site-nav">
<span>当前位置 : </span><a href="/schoolnet/login.do?flag=goIndexUI">首页</a>
<a href="/schoolnet/login.do?flag=goHomeUI" title="">个人主页</a>小说
</div>
<div class="page-news">
<div class="content">
<div class="mes_response" id="mes_response">
<table>
<tr><th class="news-time">小说</th> </tr>
<tr>
<td><span class="pages"> <a class="current"
href="javascript:void(0)"
onclick="javascript:window.history.go(-1)">返回</a> </span> <span
style="margin-left:220px">${xiaoshuo.title }</span></td>
</tr>
<tr>
<td class="pages"><c:forEach var="i" begin="1"
end="${count}">
<a class="pagesa" href="/schoolnet/xiaoshuo.do?flag=goxiaoshuodisplay&pageNow=${i }&id=${xiaoshuo.id}">第${i}章</a>
</c:forEach></td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
<jsp:include page="../public/foot.jsp" />
</div>
</body>
</html>
4、小说内容阅读页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!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="X-UA-Compatible" content="IE=edge, chrome=1" />
<meta name="renderer" content="webkit" />
<meta name="Keywords" content="个人主页、说说、相册、好友、日志、音乐、新闻、新鲜事" />
<meta name="Description" content="超酷的校园网、校园交友平台,创新的校园资源获取与分、专注打造最好的校园真实社交网络!" />
<title>校园新小说页面_校园网</title>
</head>
<body>
<div id="wrapper">
<jsp:include page="../public/head.jsp" />
<div id="page_main" class="clearfix">
<div class="page-right">
<div class="site-nav">
<span>当前位置 : </span><a href="/schoolnet/login.do?flag=goIndexUI">首页</a>
<a href="/schoolnet/login.do?flag=goHomeUI" title="">个人主页</a>小说
</div>
<div class="page-news">
<div class="content">
<div class="mes_response" id="mes_response">
<table>
<tr><th class="news-time">小说 </th></tr>
<div class="pages" style="margin-left:200px;">
</div>
<tr> <td align="center"><span>${xiaoshuo.title }</span> </td> </tr>
<tr>
<td>${str }
</td> </tr>
</table>
</div>
<div class="pages" style="margin-left:200px;">
<a href="/schoolnet/xiaoshuo.do?flag=goxiaoshuodisplay&pageNow=${page-1 }&id=${xiaoshuo.id}"
class="current"> 上一章 </a>
<a href="/schoolnet/xiaoshuo.do?flag=goxiaoshuoshowUI&pageNow=${page }&id=${xiaoshuo.id}"
class="current"> 目录</a>
<a href="/schoolnet/xiaoshuo.do?flag=goxiaoshuodisplay&pageNow=${page+1 }&id=${xiaoshuo.id}"
class="current"> 下一章</a>
</div>
</div>
</div>
</div>
</div>
<jsp:include page="../public/foot.jsp" />
</div>
</body>
</html>
相关java代码
int PagesSize=10;
String pageNow=request.getParameter("pageNow");
String id=request.getParameter("id");
//选择小说类型为全部
if("all".equals(id)){
//分页查询
int pageNows=Integer.valueOf(pageNow);
int allrows=userService.queryallrows("from Xiaoshuo", null);
int PageCount=(allrows-1)/PagesSize+1;
if(pageNows<1)
{
pageNows=1;
}
if(pageNows>PageCount)
{
pageNows=PageCount;
}
//获取小说
List<Xiaoshuo> xiaoshuos=userService.executeQueryByPage("from Xiaoshuo order by id desc", null, pageNows, PagesSize);
//获取小说分类
List<Xiaoshuotype> xiaoshuotypes=userService.getResult("from Xiaoshuotype", null);
request.setAttribute("xiaoshuotypes", xiaoshuotypes);
request.setAttribute("xiaoshuos", xiaoshuos);
request.setAttribute("pageNow", pageNows);
request.setAttribute("PageCount", PageCount);
request.setAttribute("allrows", allrows);
}
//获取连载中的小说
else if("lianzai".equals(xiaoshuotypeid)){
List<Xiaoshuo> xiaoshuos=universityService.executeQueryByPage("from Xiaoshuo where state=1 order by id desc", null, pageNow, pageSize);
}
//获取已完结的小说
else if("wanjie".equals(xiaoshuotypeid)){
List<Xiaoshuo> xiaoshuos=universityService.executeQueryByPage("from Xiaoshuo where state=2 order by id desc", null, pageNow, pageSize);
}
//选择小说类型为单类
else {
int pageNows=Integer.valueOf(pageNow);
int allrows=userService.queryallrows("from Xiaoshuo where xiaoshuotype.id=?", new Object[]{Integer.valueOf(id)});
int PageCount=(allrows-1)/PagesSize+1;
if(pageNows<1)
{
pageNows=1;
}
if(pageNows>PageCount)
{
pageNows=PageCount;
}
List<Xiaoshuo> xiaoshuos=userService.executeQueryByPage("from Xiaoshuo where xiaoshuotype.id=? order by id desc", new Object[]{Integer.valueOf(id)}, pageNows, PagesSize);
List<Xiaoshuotype> xiaoshuotypes=userService.getResult("from Xiaoshuotype", null);
request.setAttribute("xiaoshuotypes", xiaoshuotypes);
request.setAttribute("xiaoshuos", xiaoshuos);
request.setAttribute("pageNow", pageNows);
request.setAttribute("PageCount", PageCount);
request.setAttribute("allrows", allrows);
}
String id=request.getParameter("id");
Xiaoshuo xiaoshuo=(Xiaoshuo) userService.findById(Xiaoshuo.class, Integer.valueOf(id));
request.setAttribute("xiaoshuo", xiaoshuo);
String docu=xiaoshuo.getDocu();
StringBuffer sb=GetContent.uploadHead(request,docu);
Pattern p = Pattern.compile("第[一二三四五六七八九十百千]{5}章 ");
Matcher m = p.matcher(sb);
int count =0;
int count1=Integer.valueOf(request.getParameter("pageNow"));
while(m.find()){
count ++;
}
if(count1<1)
{
count1=1;
}
if(count1>count)
{
count1=count;
}
if(count1<=count)
{
//将阿拉伯数值转成中文数值
String result=ChinUtil.toChin(String.valueOf(count1));
String result2=ChinUtil.toChin(String.valueOf(count1+1));
//截取两章之间的内容
String sb1=sb.toString().substring(sb.indexOf("第"+result+"章"), sb.indexOf("第"+result2+"章"));
request.setAttribute("str", sb1);
request.setAttribute("page", count1);
}
request.setAttribute("count", count);
GetContent.java
public class GetContent {
public static StringBuffer uploadHead(HttpServletRequest request,String docu){
StringBuffer sb = new StringBuffer();
try{
//filePath就是当前这个web应用是绝对路径
String filepath=request.getSession().getServletContext().getRealPath("/");
File f2=new File(filepath+"\\Media\\txt\\"+docu);
BufferedReader bReader=new BufferedReader(new FileReader(f2));
while (true) {
String str = bReader.readLine();
if (str != null) {
sb.append(str + "<br/>");
}
if (str == null) {
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return sb;
}
}
ChinUtil.java
public class ChinUtil{
public static String toChin(String string) {
String nums[]={"0","1","2","3","4","5","6","7","8","9"};
String chines[]={"零","一","二","三","四","五","六","七","八","九"};
String level[]={"十","百","千","万","十","百","千","亿"};
//不算进制,直接将阿拉伯数值转中文数字
for (int i = 0; i < nums.length; i++) {
string=string.replaceAll(nums[i], chines[i]);
}
System.out.println(string);
StringBuffer stringBuffer=new StringBuffer(string);
//插入十进制单位
for (int i = 0; i < string.length()-1; i++) {
stringBuffer.insert(string.length()-1-i, level[i]);
}
System.out.println(stringBuffer.toString());
String temp = new String(stringBuffer.toString());
//处理零的情况
while((temp.indexOf("零万")!=-1)||(temp.indexOf("零千")!=-1)||(temp.indexOf("零百")!=-1)||(temp.indexOf("零十")!=-1)||(temp.indexOf("零零")!=-1)){
if(temp.indexOf("零千")!=-1){
temp = temp.replaceAll("零千","零");
}
if(temp.indexOf("零百")!=-1){
temp = temp.replaceAll("零百","零");
}
if(temp.indexOf("零十")!=-1){
temp = temp.replaceAll("零十","零");
}
if(temp.indexOf("零零")!=-1){
temp = temp.replaceAll("零零","零");
}
if((temp.indexOf("零万")!=-1)){
temp = temp.replaceAll("零万","万");
}
}
//处理个位为零的情况
if(temp.lastIndexOf("零")==temp.length()-1){
temp = temp.substring(0,temp.length()-1);
}
return temp;
}
}
其他相关文章