找不到符号!

adisheng 2009-09-16 09:55:16
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package mail;

/**
*
* @author Administrator
*/
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.Properties;

import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.Address;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeUtility;









public class Mail {
/** 发件方式 - 普通发送 */
final public static int TO = 0;
/** 发件方式 - 抄送 */
final public static int CC = 1;
/** 发件方式 - 密件抄送 */
final public static int BCC = 2;

/** 邮件相关信息 - SMTP 服务器 */
private String mailSMTPHost = null;
/** 邮件相关信息 - 邮件用户名 */
private String mailUser = null;
/** 邮件相关信息 - 密码 */
private String mailPassword = null;
/** 邮件相关信息 - 发件人邮件地址 */
private String mailFromAddress = null;
/** 邮件相关信息 - 邮件主题 */
private String mailSubject = "";
/** 邮件相关信息 - 邮件发送地址 */
private Address[] mailTOAddress = null;
/** 邮件相关信息 - 邮件抄送地址 */
private Address[] mailCCAddress = null;
/** 邮件相关信息 - 邮件密件抄送地址 */
private Address[] mailBCCAddress = null;
/** 邮件相关信息 - 邮件正文(复合结构) */
private MimeMultipart mailBody = null;

public Mail() {
mailBody = new MimeMultipart();
}

/**
* 设置 SMTP 服务器
* @param strSMTPHost 邮件服务器名称或 IP
* @param strUser 邮件用户名
* @param strPassword 密码
*/
public void setSMTPHost(String strSMTPHost, String strUser,
String strPassword) {
this.mailSMTPHost = strSMTPHost;
this.mailUser = strUser;
this.mailPassword = strPassword;
}

/**
* 设置邮件发送地址
* @param strFromAddress 邮件发送地址
*/
public void setFromAddress(String strFromAddress) {
this.mailFromAddress = strFromAddress;
}

/**
* 设置邮件目的地址
* @param strAddress 邮件目的地址列表, 不同的地址可用;号分隔
* @param iAddressType 邮件发送方式 (TO 0, CC 1, BCC 2) 常量已在本类定义
* @throws AddressException
*/
public void setAddress(String strAddress, int iAddressType) throws
AddressException {
switch (iAddressType) {
case Mail.TO: {
ArrayList alAddress = StringHelper.split(strAddress, ';');
mailTOAddress = new Address[alAddress.size()];
for (int i = 0; i < alAddress.size(); i++) {
mailTOAddress[i] = new InternetAddress( (String) alAddress.get(i));
}
break;
}
case Mail.CC: {
ArrayList alAddress = StringHelper.split(strAddress, ';');
mailCCAddress = new Address[alAddress.size()];
for (int i = 0; i < alAddress.size(); i++) {
mailCCAddress[i] = new InternetAddress( (String) alAddress.get(i));
}
break;
}
case Mail.BCC: {
ArrayList alAddress = StringHelper.split(strAddress, ';');
mailBCCAddress = new Address[alAddress.size()];
for (int i = 0; i < alAddress.size(); i++) {
mailBCCAddress[i] = new InternetAddress( (String) alAddress.get(i));
}
break;
}
}
}

/**
* 设置邮件主题
* @param strSubject 邮件主题
*/
public void setSubject(String strSubject) {
this.mailSubject = strSubject;
}

/**
* 设置邮件文本正文
* @param strTextBody 邮件文本正文
* @throws MessagingException
*/
public void setTextBody(String strTextBody) throws MessagingException {
MimeBodyPart mimebodypart = new MimeBodyPart();
mimebodypart.setText(strTextBody, "GBK");
mailBody.addBodyPart(mimebodypart);
}

/**
* 设置邮件超文本正文
* @param strHtmlBody 邮件超文本正文
* @throws MessagingException
*/
public void setHtmlBody(String strHtmlBody) throws MessagingException {
MimeBodyPart mimebodypart = new MimeBodyPart();
mimebodypart.setDataHandler(new DataHandler(strHtmlBody, "text/html;charset=GBK"));
mailBody.addBodyPart(mimebodypart);
}

/**
* 设置邮件正文外部链接 URL, 信体中将包含链接所指向的内容
* @param strURLAttachment 邮件正文外部链接 URL
* @throws MessagingException
* @throws MalformedURLException
*/
public void setURLAttachment(String strURLAttachment) throws
MessagingException, MalformedURLException {
MimeBodyPart mimebodypart = new MimeBodyPart();
mimebodypart.setDataHandler(new DataHandler(new URL(strURLAttachment)));
mailBody.addBodyPart(mimebodypart);
}

/**
* 设置邮件附件
* @param strFileAttachment 文件的全路径
* @throws MessagingException
* @throws UnsupportedEncodingException
*/
public void setFileAttachment(String strFileAttachment) throws
MessagingException, UnsupportedEncodingException {
File path = new File(strFileAttachment);
if (!path.exists() || path.isDirectory()) {
return;
}
String strFileName = path.getName();
MimeBodyPart mimebodypart = new MimeBodyPart();
mimebodypart.setDataHandler(new DataHandler(new FileDataSource(
strFileAttachment)));
// modified by zord @ 2003/6/16 to support Chinese File Name
// mimebodypart.setFileName(strFileName);
mimebodypart.setFileName(MimeUtility.encodeText(strFileName));
// end of modify
mailBody.addBodyPart(mimebodypart);
}

/**
* 邮件发送(一次发送多个地址, 优点速度快, 但是有非法邮件地址时将中断发送操作)
* @throws MessagingException
*/
public void sendBatch() throws MessagingException {
Properties properties = new Properties();
properties.put("mail.smtp.host", this.mailSMTPHost);
Session session = Session.getInstance(properties, null);
MimeMessage mimemessage = new MimeMessage(session);
mimemessage.setFrom(new InternetAddress(this.mailFromAddress));
if (mailTOAddress != null) {
mimemessage.addRecipients(javax.mail.Message.RecipientType.TO,
this.mailTOAddress);
}
if (mailCCAddress != null) {
mimemessage.addRecipients(javax.mail.Message.RecipientType.CC,
this.mailCCAddress);
}
if (mailBCCAddress != null) {
mimemessage.addRecipients(javax.mail.Message.RecipientType.BCC,
this.mailBCCAddress);
}
mimemessage.setSubject(this.mailSubject);
mimemessage.setContent(this.mailBody);
mimemessage.setSentDate(new Date());
Transport transport = session.getTransport("smtp");
transport.connect(this.mailSMTPHost, this.mailUser, this.mailPassword);
Transport.send(mimemessage);
System.out.println("已向下列邮箱发送了邮件");
if (mailTOAddress != null) {
for (int i = 0; i < mailTOAddress.length; i++) {
System.out.println(mailTOAddress[i]);
}
}
if (mailCCAddress != null) {
for (int i = 0; i < mailTOAddress.length; i++) {
System.out.println(mailCCAddress[i]);
}
}
if (mailBCCAddress != null) {
for (int i = 0; i < mailTOAddress.length; i++) {
System.out.println(mailBCCAddress[i]);
}
}
}
}

以上是我在网上搜到的一个发邮件的mail类,main()方法就不贴出来了。运行的时候报错:
D:\My Documents\NetBeansProjects\Mail\src\mail\Mail.java:116: 找不到符号
符号: 变量 StringHelper
位置: 类 mail.Mail
ArrayList alAddress = StringHelper.split(strAddress, ';');

是不是缺少import org.hibernate.util.StringHelper这个包啊?请高手指点,谢谢...

...全文
655 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
adisheng 2009-09-18
  • 打赏
  • 举报
回复
lvbang_lzt,你好,可说的详细点吗?
yangyanan1987 2009-09-16
  • 打赏
  • 举报
回复
哪里StringHelper的定义,导包试试
司机 2009-09-16
  • 打赏
  • 举报
回复
贴得太长了吧。。。。。。。
lzh_me 2009-09-16
  • 打赏
  • 举报
回复
ArrayList alAddress = StringHelper.split(strAddress, ';');

StringHelper是String类型的话.split函数有这个用法吗?返回的应该String[]数组。
gesanri 2009-09-16
  • 打赏
  • 举报
回复
你直接ctrl + shift + o导入包试试,不行的话是不是它自定义的类
lzh_me 2009-09-16
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 adisheng 的回复:]
引用 2 楼 lvbang_lzt 的回复:
ArrayList alAddress = StringHelper.split(strAddress, ';');

StringHelper是String类型的话.split函数有这个用法吗?返回的应该String[]数组。

是类型不兼容的问题.


[/Quote]


import org.hibernate.util.StringHelper; //导包

String tableList = params.getProperty("tables"); //

String[] tables = StringHelper.split(", ", tableList); //使用
adisheng 2009-09-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 lvbang_lzt 的回复:]
ArrayList alAddress = StringHelper.split(strAddress, ';');

StringHelper是String类型的话.split函数有这个用法吗?返回的应该String[]数组。
[/Quote]
是类型不兼容的问题.

adisheng 2009-09-16
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 gesanri 的回复:]
你直接ctrl + shift + o导入包试试,不行的话是不是它自定义的类
[/Quote]

是类型不兼容的问题.
huangan0301 2009-09-16
  • 打赏
  • 举报
回复
ddddddddddd
adisheng 2009-09-16
  • 打赏
  • 举报
回复
我导入了 hibernate3.jar 包.又报了新的错误。如下:

D:\My Documents\NetBeansProjects\Mail\src\mail\Mail.java:120: 找不到符号
符号: 方法 split(java.lang.String,char)
位置: 类 org.hibernate.util.StringHelper
ArrayList alAddress =StringHelper.split(strAddress, ';');


难道是包导入错误吗?

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧