Java迭代器通过电子邮件发送字符串图像?
我正在发送一封电子邮件,从数据库获取各种数量的图像。电子邮件将通过将字符串放在一起发送。有一个
String topEmail;
String middleEmail: (This needs to be all the images)
String bottomEmail;
电子邮件消息将 b
String emailMessag = topemail + middleEmail + bottomEmail;
我正在使用它来迭代图像
while (scdIterator.hasNext()) {
middleEmail= "<div><img src=\"someimg1.jpg"\" height=\"115\"></div>";
}
,并且无论有多少图像都需要作为
示例
<div><img src=\"someimg1.jpg"\" height=\"115\"></div>
<div><img src=\"someimg2.jpg"\" height=\"115\"></div>
<div><img src=\"someimg3.jpg"\" height=\"115\"></div>
I am sending out an email that gets a variety number of images from a db. The email will be sent from putting Strings together. There is a
String topEmail;
String middleEmail: (This needs to be all the images)
String bottomEmail;
The email message will b
String emailMessag = topemail + middleEmail + bottomEmail;
I am using this to iterate the images
while (scdIterator.hasNext()) {
middleEmail= "<div><img src=\"someimg1.jpg"\" height=\"115\"></div>";
}
and need no matter how many image there are the outcome to be
example
<div><img src=\"someimg1.jpg"\" height=\"115\"></div>
<div><img src=\"someimg2.jpg"\" height=\"115\"></div>
<div><img src=\"someimg3.jpg"\" height=\"115\"></div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不断用全新的值替换
middleEmail
,而不是将新信息附加到前一个值的末尾。换句话说,您需要从各个部分逐渐构建一个字符串。在 Java 中,逐段构建字符串的典型方法是使用 StringBuilder。尝试这样的事情:
You keep replacing
middleEmail
with a totally new value, instead of appending new information to the end of the previous value. In other words, you need to gradually build up a String from its parts. In Java, the typical way to build up a String piece-by-piece is to use a StringBuilder.Try something like this:
您实际上并没有说出您的问题是什么,但是...您正在迭代某些内容,但实际上并未从迭代器中读取值。
也许你想要这样的东西:
...如果你的迭代器返回文件名
(并查看 gteff 关于 StringBuilder 的答案 - 你也需要它)
You don't actually say what your problem is, but... you are iterating over something, but not actually reading the values from the iterator.
Perhaps you want something like:
...if your iterator returns filenames
(and see gteff's answer about StringBuilder - you need that too)
最好不要在 java 代码中构造 html 字符串,您可以使用任何模板引擎,例如 StringTemplates,它可以帮助您。
Its always better not to construct html strings inside java code, you could use any templating engine like StringTemplates, which can help you.