zoukankan      html  css  js  c++  java
  • Blog 使用Jsoup解析出html中的img元素

    Jsoup主页:http://jsoup.org/

    在Blog.java 加入

        private List<String> imageList=new LinkedList<String>(); // 博客里存在的图片,主要用于列表展示的缩略图

        for(Blog blog:blogList){
                List<String> imageList=blog.getImageList();
                String blogInfo=blog.getContent();
                Document doc=Jsoup.parse(blogInfo);
                Elements jpgs=doc.select("img[src$=.jpg]");
                for(int i=0;i<jpgs.size();i++){
                    Element jpg=jpgs.get(i);
                    imageList.add(jpg.toString());
                    if(i==2){
                        break;
                    }
                }
            }
    View Code
        <span class="img">
                                  <c:forEach var="image" items="${blog.imageList }">
                                      <a href="/blog/articles/${blog.id }.html">${image}</a>
                                      &nbsp;&nbsp;
                                  </c:forEach>
                              </span>
    <span class="img">
    <a href="/blog/articles/50.html">
    <img src="/static/userImages/20160214/1455425736515085353.jpg" title="1455425736515085353.jpg" alt="QQ鎴�浘20160214125257.jpg">
    </a>
    </span>

    如果发现图片显示不出来,需要设置tomcat的项目路径,因为实际在网上的项目是不带名字的,直接是IP域名

    开发环境如何运行web项目不带项目名字

    http://blog.java1234.com/blog/articles/58.html

  • 相关阅读:
    Codeforces Round #456 (Div. 2)
    Codeforces Round #455 (Div. 2)
    Codeforces Round #453 (Div. 1)
    Codeforces Round #450 (Div. 2)
    退役了
    退役了
    这个博客不想要了
    Hello!The familiar and strange world.
    真正的退役了。
    bzoj4231: 回忆树
  • 原文地址:https://www.cnblogs.com/skyislimit/p/6071929.html
Copyright © 2011-2022 走看看