免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2139 | 回复: 7
打印 上一主题 下一主题

jsp如何执行函数中的数组 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-12-02 11:29 |只看该作者 |倒序浏览
bean文件里有个
发送邮件的函数,但接收人是emailList = {"xx@xx.com", "xx@xx.com"};数组的形式。
postMail( String recipients[], String subject,
  //public void postMail( String recipients, String subject,
                            String message , String from)

在jsp中该如何调用该函数。
这样执行会出错,因为是接收人是一个数组。应该怎么写,谢谢了。:)
mail.postMail("recipient@xx.com", "Test", "Welcome to javaMail", "xx@xx.com");

论坛徽章:
0
2 [报告]
发表于 2005-12-02 12:19 |只看该作者
应该是个简单的问题吧。

论坛徽章:
0
3 [报告]
发表于 2005-12-02 14:09 |只看该作者
首先不知 postMail 是怎么写的

改 postMail( String recipients[], String subject,................

这样来传数组应该没错,为什么你判断错误就 这 postMail( String recipients[], String subject,...........

而不在 postMail 里呢?

论坛徽章:
0
4 [报告]
发表于 2005-12-02 14:45 |只看该作者
postMail函数如下,主要是 emailList是数组文件。调用的时候没有法用单个String。不知道应该怎么样调用。谢谢


  1. private static final String[] emailList = {"[email]xx@xx.com[/email]", "[email]xx@xx.com[/email]"};
  2.   public static void main(String args[]) throws Exception
  3.   {
  4.     SendMailUsingAuthentication smtpMailSender = new SendMailUsingAuthentication();    smtpMailSender.postMail( emailList, emailSubjectTxt, emailMsgTxt, emailFromAddress);
  5.     System.out.println("Sucessfully Sent mail to All Users");
  6.   }



  7. public void postMail( String recipients[], String subject,
  8.   //public void postMail( String recipients, String subject,
  9.                             String message , String from) throws MessagingException
  10.   {
  11.     boolean debug = false;

  12.      //Set the host smtp address
  13.      Properties props = new Properties();
  14.      props.put("mail.smtp.host", SMTP_HOST_NAME);
  15.      props.put("mail.smtp.auth", "true");

  16.     Authenticator auth = new SMTPAuthenticator();
  17.     Session session = Session.getDefaultInstance(props, auth);

  18.     session.setDebug(debug);

  19.     // create a message
  20.     Message msg = new MimeMessage(session);

  21.     // set the from and to address
  22.     InternetAddress addressFrom = new InternetAddress(from);
  23.     msg.setFrom(addressFrom);

  24.     InternetAddress[] addressTo = new InternetAddress[recipients.length];
  25.     for (int i = 0; i < recipients.length; i++)
  26.     {
  27.         addressTo[i] = new InternetAddress(recipients[i]);
  28.     }
  29.     msg.setRecipients(Message.RecipientType.TO, addressTo);

  30.    // msg.setRecipient(Message.RecipientType.TO,toemail);
  31.     // Setting the Subject and Content Type
  32.     msg.setSubject(subject);
  33.     msg.setContent(message, "text/plain");
  34.     Transport.send(msg);
  35. }
复制代码

[ 本帖最后由 jiarry 于 2005-12-2 14:47 编辑 ]

论坛徽章:
0
5 [报告]
发表于 2005-12-02 14:49 |只看该作者
问题查明是调用的方式不正确,在eclipse里也有提示。说不能以String替代数组来传递什么的。
总之,如果传递数组,应该怎么改?

论坛徽章:
0
6 [报告]
发表于 2005-12-02 14:51 |只看该作者
提示什么?

假如原来发单封的方法是可以的

那简单点,你循环那个 EMAIL 列表,然后调用按个 可行 的吧,这样少去你的调试时间了

论坛徽章:
0
7 [报告]
发表于 2005-12-02 15:07 |只看该作者
可是我要从页面上来调用这个函数。只有一个接收人。
mail.postMail("recipient@xx.com", "Test", "Welcome to javaMail", "xx@xx.com"); 这样调用就不行。"recipient@xx.com"这项应该怎么样调用它??

论坛徽章:
0
8 [报告]
发表于 2005-12-02 17:13 |只看该作者



  1. String r = new String[1];
  2. r[0] = "xx@xx.com";

  3. mail.postMail(r,.................);
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP