【问题标题】:HTML images in HTMLPanelHTMLPanel 中的 HTML 图像
【发布时间】:2014-07-28 17:41:52
【问题描述】:

这是我的问题。例如,我有一些 HTML 文件 Description.html,它包含类似这样的内容

<p>
    <img src="Bill.jpg">
</p>

Bill.jpg 与 html 文件在同一目录中。

我还有 UiBinder 小部件,其中包含称为 panelSimplePanel。 在这个小部件的 ui.xml 中看起来像

...
<ui:style src="../Style.css"/>

    <g:SimplePanel ui:field="panel" addStyleNames="{style.description}" />
...

这个小部件的构造函数是:

public SomeWidget() {
        initWidget(uiBinder.createAndBindUi(this));
        panel.setWidget(new HTMLPanel(HtmlTextResources.htmlFile().getText());
    }

问题的关键 - bill.img 不显示。 控制台显示

> [WARN] 404 - GET /bill.jpg (127.0.0.1) 1373 bytes    Request headers
>       Host: 127.0.0.1:8888
>       Connection: keep-alive
>       Cache-Control: no-cache
>       Accept: image/webp,*/*;q=0.8
>       Pragma: no-cache
>       User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153
> Safari/537.36
>       *****************
>       Accept-Encoding: gzip,deflate,sdch
>       Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4,it;q=0.2,uk;q=0.2    Response
> headers
>       Content-Type: text/html;charset=ISO-8859-1
>       Cache-Control: must-revalidate,no-cache,no-store
>       Content-Length: 1373

我该如何解决这个问题?需要通过html使用图片

【问题讨论】:

  • 如果没有进一步的了解,我猜“bill.jpg”不在您的服务器提供的根文件夹中。也许它存在于子目录中。也许stackoverflow.com/questions/15071517/… 是有价值的。

标签: java html gwt gxt uibinder


【解决方案1】:

您的 GWT 应用程序中的任何相对 URL 通常是相对于您的 WEB-INF 目录(或 web.xml 所在的任何目录被调用)读取的。与您的 HTML 页面所在的目录无关。

因此,如果您不想替换 Description.html 中的所有 URL,则应将引用的文件移至 WEB-INF。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-26
    • 1970-01-01
    • 1970-01-01
    • 2012-02-14
    • 2011-02-04
    • 2011-07-19
    • 1970-01-01
    • 2010-11-07
    相关资源
    最近更新 更多