【发布时间】:2019-07-02 23:47:25
【问题描述】:
在 GWT 中,我有一个 servlet,它将图像从数据库返回到客户端。我需要提取部分字符串以正确显示图像。 chrome、firefox 和 IE 中返回的内容在 src 部分有一个斜线。例如:String s = "src=\""; 这在下面的字符串中不可见。可能斜线在 http 字符串周围添加了更多括号。我不确定?
what is returned in those 3 browsers is = <img style="-webkit-user-select: none;" src="http://localhost:8080/dashboardmanager/downloadfile?entityId=4886">
EDGE 浏览器在 src 中没有斜杠,所以我提取图像的方法在边缘不起作用
边缘返回什么:
String edge = "<img src=”http://localhost:8080/dashboardmanager/downloadfile?entityId=4886”>";
问题:我需要提取下面的字符串。
http://localhost:8080/dashboardmanager/downloadfile?entityId=4886
使用 src= 或 src=\
我在没有括号 "src=\" 的情况下返回的浏览器上尝试并使用了什么:
String s = "src=\"";
int index = returned.indexOf(s) + s.length();
image.setUrl(returned.substring(index, returned.indexOf("\"", index + 1)));
但在 EDGE 中无法工作,因为它不返回斜线
我无法访问 GWT 中的 Pattern 和 matcher。
我如何提取并记住 entityId 编号会改变 http://localhost:8080/dashboardmanager/downloadfile?entityId=4886
上面的返回什么字符串?
编辑:
我需要一个通用的方法来提取http://localhost:8080/dashboardmanager/downloadfile?entityId=4886
当字符串可能看起来像这两种方式时。
String edge = "<img src=”http://localhost:8080/dashboardmanager/downloadfile?entityId=4886”>";
3 browsers is = <img style="-webkit-user-select: none;" src="http://localhost:8080/dashboardmanager/downloadfile?entityId=4886">
【问题讨论】: