私のコード(Javaにあります)では、メールの件名に特定の文字列の出現が計算されています。その情報を表形式で表示するメールを送信することになっています。テーブルには、その文字列の "文字列名"と "カウント値"の2つのフィールドが含まれています。私はそれを行うことができますが、私は文字列のカウント値が0に等しい文字列のカウント値を表示したくありません。カウント変数は、その文字列が発生したときに1だけインクリメントします(count ++)。メールを送信するときに、htmlテーブルにカウント値(0に等しい)を表示しないようにします。
私はテーブル(html形式)で必要なときに番号と空文字列の両方を表示できるカウント変数に対してObjectコンベンションを選択することを考えていましたが、その増分をObject変数で実行することはできません。
この問題を解決する方法はありますか?以下は
コードスニペットです:
public static void main(String[] args) throws MessagingException{
String host = "smtp.gmail.com", senderid = "<sender_id>@gmail.com", recipient = "<recipient_id>@gmail.com";
String password = "*******";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", "587");
// Get the Session object.
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(senderid, password);
}
});
System.out.println("Sending mail");
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(senderid));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(recipient));
message.setSubject("Test");
message.setContent(<table_format stored a string which accesses the count variable in its <td> tag>, "text/html");
Transport.send(message);
System.out.println("Done");
}
これは動作するコードスニペットです。カウント値は別のクラスから来ています。私はちょうど表の0であるカウント値の表示をスキップしたいと思う。
ありがとうございました。
ゼロカウントを削除する場所のようなサウンドは、ここで結果文字列を解析する代わりに、ゼロカウントを返すコードにあります。あなたはそのコードを共有できますか? – Mureinik
@Mureinikがコードスニペットを追加しました。 – Nikhil