Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用java更新html div内容_Java_Jsoup - Fatal编程技术网

如何使用java更新html div内容

如何使用java更新html div内容,java,jsoup,Java,Jsoup,我正在开发一个JavaRCP应用程序。每当用户更新UI中的详细信息时,我们也会在html报告中更新相同的详细信息。是否有一个方法可以使用java更新/添加html元素。使用Jsoup,我能够获得所需的元素ID,但无法为其插入/更新新元素 Document htmlFile = null; try { htmlFile = Jsoup.parse(new File("C:\\ItemDetails1.html"), "UTF-8"); } catch (IOExc

我正在开发一个JavaRCP应用程序。每当用户更新UI中的详细信息时,我们也会在html报告中更新相同的详细信息。是否有一个方法可以使用java更新/添加html元素。使用Jsoup,我能够获得所需的元素ID,但无法为其插入/更新新元素

Document htmlFile = null;

    try {
        htmlFile = Jsoup.parse(new File("C:\\ItemDetails1.html"), "UTF-8");
    } catch (IOException e) {
        e.printStackTrace();
    }
    Element div = htmlFile.getElementById("row2_comment");
    System.out.println("text: " + div.html());
    div.html("<li><b>Comments</b></li><ul><li>Testing for comment</li></ul>");
文档htmlFile=null;
试一试{
htmlFile=Jsoup.parse(新文件(“C:\\ItemDetails1.html”),“UTF-8”);
}捕获(IOE异常){
e、 printStackTrace();
}
Element div=htmlFile.getElementById(“行2_注释”);
System.out.println(“文本:+div.html());
div.html(“
  • 评论
    • 测试评论
    ”;
    有什么想法吗

    Try:
    
    Element div = 
     htmlFile.getElementById("row2_comment");
    
     div.appendElement("p").attr("class", 
     "beautiful").text("Some New Text")
    

    要添加具有某种样式和文本内容的新段落,这将更新内存中的div元素,但不会更新实际html文件中的div元素。当我关闭并重新打开该文件时,我看不到任何更改。要保存该文件,请执行以下操作:file input=new file(“C:\\itemdails1.html”);PrintWriter=新的PrintWriter(输入,“UTF-8”);然后进行修改和:writer.write(htmlFile.html());writer.flush();writer.close();