【问题标题】:Look for string in arraylist element and pair it with specific image在 arraylist 元素中查找字符串并将其与特定图像配对
【发布时间】:2016-01-31 17:53:56
【问题描述】:

我正在尝试使用 Model 、 JSP 和 Servlet 做一个 MVC 应用程序。

从我的模型中我得到一个数组列表:

ArrayList<String> myArrayList = new ArrayList<String>();

每个元素看起来像这个例子:96125;www.qwerty.com 假设我有一个名为:www.qwerty.com.png

我想将 myArrayList 从我的 servlet 传递给 jsp。所以假设我调用 myArrayList[0] 并且第一个元素是 96125;www.qwerty.com 我希望它在我的 JSP 中显示图像 www.qwerty.com.png 而不是实际元素。

我该如何解决这个问题?

【问题讨论】:

  • 使用 html img 标签www.qwerty.com.png&lt;img src="www.qwerty.com.png"/&gt;
  • 我不能那样做。因为 element[1] 可能是:213231;www.asdfgh.com 并且第二天 element[1] 将是 element[0]。
  • 你的 JSP 文件是什么样的?
  • 它只是一个从 Eclipse 自动生成的普通 JSP 文件

标签: java image jsp servlets arraylist


【解决方案1】:

如果只获取图片名称,可以使用String类的split方法:

    myArrayList[0].split(";")[1]

【讨论】:

    猜你喜欢
    • 2016-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-05
    • 2021-03-19
    • 1970-01-01
    • 2016-05-09
    相关资源
    最近更新 更多