【问题标题】:Image is not coming in Jquery POP Up图像没有出现在 Jquery POP Up 中
【发布时间】:2015-09-10 19:50:10
【问题描述】:
String mailBody = "<div style='margin-left:10px;'>"
                       +"<div style='font-weight: bold; font-size: 19px; padding-top: 8px;'>Anindya</div>"
                       +"<div style='font-size: 17px;'>Senior Salesforce with Oracle Developer</div>"
                       +"<div style='margin-top:5px;padding-bottom: 4px; font-size: 12px;'><img src="+resourceRequest.getContextPath()+"/images/icon/Mobile-phone.png\" height='16' width='16'></img>9830093200</div>"
                       +"<div style='padding-bottom: 4px; font-size: 12px;'><img src='../images/icon/location-icon.png' height='16' width='16'></img>Kolkata</div>"
                       +"<div style='display:inline-block;padding-bottom: 4px; font-size: 12px;'><img src='../images/icon/email-icon.png' height='16' width='16' style='float:left;margin-right:2px;'></img><div style='float:left;'>anindyamallik@gmail.com</div></div>"
                       +"</div>";

I want to show this string in a pop up, but while showing to pop up the    

图像不可用。如何解决?

谁能帮帮我吗?

【问题讨论】:

  • 你能检查生成的html吗?生成的图片 URL 是否有效?
  • 使用firebug我可以看到它显示加载图片URL失败
  • 你得到的 resourceRequest.getContextPath() 的值是多少?
  • resourceRequest.getContextPath() 一定有问题。尝试使用 request.getContextPath(),其中 request 是 httpServletRequest 对象。它将为您提供应用程序的有效上下文路径。
  • 这很容易在浏览器开发工具网络中进行故障排除。查看发送到服务器的失败 url 并进行相应调整。

标签: jquery liferay


【解决方案1】:

如果你想在你的portlet的JSP页面上获取动态上下文路径,你可以使用HttpServletRequest对象的request.getContextPath()如下:

JSP:

String mobileIcon = request.getContextPath()  + "/images/icon/Mobile-phone.png";
String locationIcon = request.getContextPath()  + "/images/icon/location-icon.png";
String emailIcon = request.getContextPath() + "/images/icon/email-icon.png";

如果你想在动作文件中获取它,例如在serveResource 方法中,您可以从PortletContext 对象中获取上下文名称,如下所示:

行动:

PortletContext portletContext = resourceRequest.getPortletSession().getPortletContext();
String mobileIcon = "/" + portletContext.getPortletContextName()  + "/images/icon/Mobile-phone.png";
String locationIcon = "/" + portletContext.getPortletContextName()  + "/images/icon/location-icon.png";
String emailIcon = "/" + portletContext.getPortletContextName()  + "/images/icon/email-icon.png";

【讨论】:

  • @Tobias Liefke,你在 Linux / Unix 环境下测试过吗?
  • File.separator 是一个静态 util 方法,它返回 \ 或 / 作为基于操作系统的字符串。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-01-03
  • 1970-01-01
  • 2016-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多