开发者

Can't display images from localhost

I dont understand why in my webAPP When I try to load an Icon by doing this for exemple :

ImageIcon rtfIcon = new ImageIcon("http://localhost:8080/app/images/rtf.gif"); 

the rtfIcon.getImageLoadStatus() returns an ERRORED value .

But in my web browser it displays properly http://localhost:8080/app/images/rtf.gif . I dont get it . I use开发者_高级运维 apache tomcat . Is there any option configuration to do or it's simple coding mistake ?

thanks in advance .


ImageIcon rtfIcon = new ImageIcon("http://localhost:8080/app/images/rtf.gif"); 

Presumes the String refers to a File. Use instead..

ImageIcon rtfIcon = new ImageIcon(
    new URL("http://localhost:8080/app/images/rtf.gif"));

..or, taking into account the advice from BalusC..

"The applet will fail to work whenever the webserver runs at a physically different machine (in production). Rather use getCodeBase() to get the URL to the host where the applet is been served from and then build further on that."

ImageIcon rtfIcon = new ImageIcon(
    new URL(getCodeBase(), "/app/images/rtf.gif"));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜