jsp怎么实现文章内容的分页显示,文章内容包含HTML标签。

没有用SSH。

看了楼上两位回答,完全不知所云,连问题点都没找到。问题中说了“文章内容包含HTML标签”,这与传分页参数和dao有关系?
内容中包含html,那就说明从数据中截取分页内容时会出现如下情况:
1。取出的分页内容中,html标签不完整(比如<a href=,后面就没了。。。),针对这种情况,我们应该实现一个向前搜索和向后搜索内容以保证html标签完整性的功能。
2。有可能出现标签不成对的情况,比如有<form>,没有</form>这种情况,那么这个问题也是我们需要去搜索内容来解决的。或者说做的过分点,我们写一个缺少结束标签的自动补足模块。
3。出现类似有</form>,但是没有<form>的情况,这就有点伤脑筋了,是向前搜索内容直到补足还是直接在保存内容时就做分页处理分页以保证<form></form>标签模块的完整性这些策略就只有楼主你来思考了,呵呵。
不知道楼主你想说的是不是这些问题呢,说实在的,对包含html的内容进行分页有点繁琐,还不如直接把内容页面做“静态化”处理,这样分页都免了。当然还有一种办法就是在用户输入内容时就做好分页工作(对用户行为做限制),这样或许会好一点
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-01-01
上个星期也遇到与你一样的问题

其实我们自己考虑不周的原因,平时一般点击“下一页”,只是把当前第几页传过去,而查找的内容没有传过去,当时不能显示我们想像的效果

所以:
1、当第一次查找时,记得一定也要把查找的内容传到页面
2、在点击“下一页”里(其它按钮也一样),要把查找的内容也传过去,如果没有,传个null也行;
3、在第二个页里,接收信息时判断一下查找的内容是否为空,从而进行是模糊查询还是列出所有信息,取得数据后,判断查找的内容如果不为空的话,再把查找的内容传到页面

这样就没有问题了

另外,代码写得缺乏可重用性本回答被网友采纳
第2个回答  2010-12-31
你用什么做的 SSH吗
第3个回答  2011-01-02
这是dao层,db层你自己写下
/**
* 新品营地
* 返回与当前时间相关months个月的商品条数
* @param months
* @return
*/
public int getAllCount(int months)
{
int allCount=0;
ConnDB connDB=new ConnDB();
Connection conn=connDB.getConn();
PreparedStatement ps=null;
ResultSet rs=null;
String sql="select count(*) from goods where MONTHS_BETWEEN(sysdate,goodsTime)<=?";
try {
ps=conn.prepareStatement(sql);
ps.setInt(1, months);
rs=ps.executeQuery();
if(rs.next())
{
allCount=rs.getInt(1);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
connDB.closeDB(conn, ps, rs);
}
return allCount;
}
/**
* 新品营地
* @param curPage
* @param perPage
* @param months
* @return
*/
public List<GoodsBean> selectNewGoods(int curPage,int perPage,int months)
{
List<GoodsBean> list=new ArrayList<GoodsBean>();
ConnDB connDB=new ConnDB();
Connection conn=connDB.getConn();
PreparedStatement ps=null;
ResultSet rs=null;
String sql="select * from (select * from goods where MONTHS_BETWEEN(sysdate,goodsTime)<=?) where GoodsName not in(select GoodsName from goods where MONTHS_BETWEEN(sysdate,goodsTime)<=? and rownum<=?) and rownum<=?";
GoodsBean g=null;
try {
ps=conn.prepareStatement(sql);
ps.setInt(1, months);
ps.setInt(2, months);
ps.setInt(3, curPage*perPage);
ps.setInt(4, perPage);
rs=ps.executeQuery();
while(rs.next())
{
g=new GoodsBean();
g.setGoodsId(rs.getInt("goodsId"));
g.setGoodsDispatcherName(rs.getString("goodsDispatcherName"));
g.setGoodsName(rs.getString("goodsName"));
g.setGoodsPrice(rs.getFloat("goodsPrice"));
g.setGoodsDiscount(rs.getFloat("goodsDiscount"));
g.setGoodsAmount(rs.getInt("goodsAmount"));
g.setGoodsType(rs.getString("goodsType"));
g.setGoodsIntroduce(rs.getString("goodsIntroduce"));
g.setGoodsPhoto(rs.getString("goodsPhoto"));
g.setGoodsCliks(rs.getInt("goodsCliks"));
g.setGoodsSalAmount(rs.getInt("goodsSalAmount"));
g.setGoodsRecommentNum(rs.getInt("goodsRecommentNum"));
g.setGoodsTime(rs.getString("goodsTime"));
list.add(g);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
connDB.closeDB(conn, ps, rs);
}
return list;
}
这是控制层
int months = 2;// 离当前时间为2个月为新品
GoodsSearchDao gsd = new GoodsSearchDao();
int allCount = gsd.getAllCount(months);//数据总条数
int perPage = 2;//每页显示多少
int numPage = 0;//总共多少页
if (allCount % perPage == 0) {
numPage = allCount / perPage;
} else {
numPage = allCount / perPage + 1;
}
request.setAttribute("numPage", numPage);
String cur = request.getParameter("cur");
int curPage = 0;
if (cur != null && !cur.equalsIgnoreCase("")) {
curPage = Integer.parseInt(cur);
}
request.setAttribute("curPage", curPage);
List<GoodsBean> goodsSearch = gsd.selectNewGoods(curPage, perPage,
months);
request.setAttribute("goodsSearch", goodsSearch);
页面层
<c:choose>
<c:when test="${curPage==0}">
首页 上一页 
</c:when>
<c:otherwise>
<a href="../goodsServlet?add=${add}&type=${type}">首页</a> <a
href="../goodsServlet?cur=${curPage-1}&add=${add}&type=${type}">上一页</a> 
</c:otherwise>
</c:choose>

<c:choose>
<c:when test="${curPage==numPage-1}">
下一页 末页
</c:when>
<c:otherwise>
<a href="../goodsServlet?cur=${curPage+1}">下一页</a> <a
href="../goodsServlet?cur=${numPage-1}">末页</a> 
</c:otherwise>
</c:choose>
这是我以前写过的,有些地方不完整