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

posted @ 2016-11-16 23:00  SKYisLimit  阅读(826)  评论(0编辑  收藏  举报