问题是这样 我在做一个新闻发布系统
因为我使用了fckeditor,我的数据库中新闻内容字段中含有大量的html标签
如:<h1>asjkldjasdfa</h1>
如何过滤掉标签,提取出新闻正文呢? 对提 取出的新闻,即单个字段的内容,又如何分页呢?
因为我使用了fckeditor,我的数据库中新闻内容字段中含有大量的html标签
如:<h1>asjkldjasdfa</h1>
如何过滤掉标签,提取出新闻正文呢? 对提 取出的新闻,即单个字段的内容,又如何分页呢?
解决方案 »
- 求助,这是怎么回事?
- jsp
- jsp页面打开后自动关闭
- [struts2]ModelDriven的一个问题
- jsp怎么做在线播放电影?
- 关于import javax.servlet.*;
- 在JSP中可以使用VML么?
- errors.add( "username", new ActionMessage("hello.dont.talk.to.monster",badUserName) );saveErrors( request, errors );这里错误在什
- 截取问题。。在线等待
- 求一问题答案,有关数据操作的
- 在myeclipse里面编辑代码,按end键不能到行的末尾
- struts 中的DispatchAction使用时的问题!!jsp!!
分页的原理是对查询出来的结果集(ResultSet,List)的一些substring()获取子集合,在页面上操作,
在网上sousou资料就会了.
* 删除input字符串中的html格式
*
* @param input
* @param length
* @return
*/
public static String splitAndFilterString(String input, int length) {
if (input == null || input.trim().equals("")) {
return "";
}
// 去掉所有html元素,
String str = input.replaceAll("\\&[a-zA-Z]{1,10};", "").replaceAll(
"<[^>]*>", "");
str = str.replaceAll("[(/>)<]", "");
int len = str.length();
if (len <= length) {
return str;
} else {
str = str.substring(0, length);
str += "......";
}
return str;
}
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;import com.fenye.vo.Answer;/**
* A data access object (DAO) providing persistence and search support for
* Answer entities. Transaction control of the save(), update() and delete()
* operations can directly support Spring container-managed transactions or they
* can be augmented to handle user-managed Spring transactions. Each of these
* methods provides additional information for how to configure it for the
* desired type of transaction control.
*
* @see com.fenye.vo.Answer
* @author MyEclipse Persistence Tools
*/
@SuppressWarnings("unchecked")
public class AnswerDAO extends BaseHibernateDAO {
private static final Log log = LogFactory.getLog(AnswerDAO.class); public List Fenye(int currentPage ,int lineSize)
{
String sql="FROM Answer order by id";
Query query=super.getSession().createQuery(sql);
query.setFirstResult((currentPage-1)*lineSize);
query.setMaxResults(lineSize);
List list=query.list();
return list;
}
public Long getallcount()
{
Long count=new Long(0);
String sql="select count(answer.id) from Answer as answer";
Query query=super.getSession().createQuery(sql); count=(Long) query.list().get(0);
System.out.println(query.list().get(0));
System.out.println(query.list().get(0).getClass());
return count;
// return null;
}
}Action代码:/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.fenye.action;import java.util.List;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;import com.fenye.dao.AnswerDAO;
//import com.fenye.form.ListAnswerForm;/**
* MyEclipse Struts
* Creation date: 05-09-2009
*
* XDoclet definition:
* @struts.action path="/listAnswer" name="listAnswerForm" input="/index.jsp" scope="request" validate="true"
*/
public class ListAnswerAction extends Action {
/*
* Generated Methods
*/ /**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
@SuppressWarnings("unchecked")
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
int lineSize=4;//每页记录数
int currentPage = 1;// 当前是第几页
Long allRecorders = new Long(0);// 全部的记录数
try {
if(request.getParameter("current")==null)
currentPage = 1;
else
currentPage = Integer.parseInt(request.getParameter("current"));
} catch (Exception e)
{
e.printStackTrace();
}
try {
allRecorders=new AnswerDAO().getallcount();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(allRecorders/lineSize);
// currentpage=Integer.parseInt(request.getParameter("cp"));
List list=new AnswerDAO().Fenye(currentPage, lineSize);
request.setAttribute("currentPage",currentPage);
request.setAttribute("lineSize",lineSize);
request.setAttribute("allRecorders",allRecorders);
request.setAttribute("list",list);
request.setAttribute("jspUrl","zb.do");
request.setAttribute("status","zhaoblist");
return mapping.findForward("Answerlist");
}
}