问题是这样 我在做一个新闻发布系统 
因为我使用了fckeditor,我的数据库中新闻内容字段中含有大量的html标签 
如:<h1>asjkldjasdfa</h1> 
如何过滤掉标签,提取出新闻正文呢? 对提 取出的新闻,即单个字段的内容,又如何分页呢? 

解决方案 »

  1.   

    document.getElementsByTagName("H1").innerHTML;
    分页的原理是对查询出来的结果集(ResultSet,List)的一些substring()获取子集合,在页面上操作,
    在网上sousou资料就会了.
      

  2.   

    我使用FCKeditor时也出现过这种问题,我的系统中主要使用了filter进行了编码转换,在添加新闻的页面中加入<bean:write property="newscontent" filter="false">就可以了!你试试看!
      

  3.   

    一般这种情况是过滤掉文章中的HTML标签,而不是把它提取出来至于过滤方法,当然就是用正则表达式了,提供给楼主一个方法做一下参考。/**
     * 删除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;
    }
      

  4.   

    下面是分页代码,LZ参考一下:package com.fenye.dao;import java.util.List;
    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");
    }
    }