Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/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 使用JSOUP在href属性中插入JSP标记_Java_Jsp_Jsoup - Fatal编程技术网

Java 使用JSOUP在href属性中插入JSP标记

Java 使用JSOUP在href属性中插入JSP标记,java,jsp,jsoup,Java,Jsp,Jsoup,我想使用Jsoup解析器将HTML页面转换为JSP页面,在源属性中注入非常简单的JSP代码 我有: <script language="text/javascript" src="toto.js"></script> 下面是我的代码摘录: Path chemin = Paths.get("D:/files.xhtml"); try (InputStream inputStream = Files.newInputStream(chemin)) { Documen

我想使用Jsoup解析器将HTML页面转换为JSP页面,在源属性中注入非常简单的JSP代码

我有:

<script language="text/javascript" src="toto.js"></script>
下面是我的代码摘录:

Path chemin = Paths.get("D:/files.xhtml");
try (InputStream inputStream = Files.newInputStream(chemin)) {
    Document document = Jsoup.parse(inputStream, StandardCharsets.UTF_8.name(),  "http://www.mywebsite.com/files.xhtml");
    cssElements = document.select("img[src], script[src]");
    for (Element element : cssElements) {
        String href = element.attr("src");
        element.attr("src", "<c:url=\"" + href + "\" />");
    }
}
Path chemin=Path.get(“D:/files.xhtml”);
try(InputStream InputStream=Files.newInputStream(chemin)){
Document Document=Jsoup.parse(inputStream,StandardCharsets.UTF_8.name(),”http://www.mywebsite.com/files.xhtml");
cssElements=document.select(“img[src],script[src]”;
对于(元素:cssElements){
String href=element.attr(“src”);
元素attr(“src”和“”);
}
}
files.xhtml包含标准HTML脚本标记或标准img标记

有没有办法避免
替换为


感谢您的支持:)

为什么要使用我想在JSP页面中转换HTML页面(只在页面顶部添加JSP库并转换一些链接),所以我需要对所有链接使用c:url JSP标记!向我们展示您尝试过的代码(Jsoup)我的原始问题是用我的代码编辑的:)
<script language="text/javascript" src="&lt;c&colon;url value=&quot;toto.js&quot;&gt;" />"></script>
Path chemin = Paths.get("D:/files.xhtml");
try (InputStream inputStream = Files.newInputStream(chemin)) {
    Document document = Jsoup.parse(inputStream, StandardCharsets.UTF_8.name(),  "http://www.mywebsite.com/files.xhtml");
    cssElements = document.select("img[src], script[src]");
    for (Element element : cssElements) {
        String href = element.attr("src");
        element.attr("src", "<c:url=\"" + href + "\" />");
    }
}