java后台操作html字符串并当作一个页面返回给浏览器
·
引入依赖包
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.10.3</version>
</dependency>后台代码如下
/**
* 操作html字符串
* @param request
* @param response
* @throws IOException
*/
@RequestMapping("WStoHtml")
public void WStoHtml(HttpServletRequest request,HttpServletResponse response) throws IOException{
String url = "http://localhost:8082/bim/static/form2/ApplicationFormTable.htm";
String body = HttpClientUtil.doPost(url);//body为获取的html代码
//System.out.println(body);
//System.out.println("11111");
Document doc = Jsoup.parse(body);
Elements es = doc.select("table");
for (Element element : es) {
element.html("123");//将table的内容替换为123
}
for (Element element : es) {
System.out.println(element.html());
}
System.out.println(doc.outerHtml());
response.setContentType("text/html;charset=utf-8");
PrintWriter out=response.getWriter();
out.println(doc.outerHtml());
}
「智能机器人开发者大赛」官方平台,致力于为开发者和参赛选手提供赛事技术指导、行业标准解读及团队实战案例解析;聚焦智能机器人开发全栈技术闭环,助力开发者攻克技术瓶颈,促进软硬件集成、场景应用及商业化落地的深度研讨。 加入智能机器人开发者社区iRobot Developer,与全球极客并肩突破技术边界,定义机器人开发的未来范式!
更多推荐



所有评论(0)