如何将具有某些动态值(操作类)的类变量附加到href
标记,以便使用java邮件API发送密码重置链接。
我的发送方法是:
public String sendEmail() {
try {
// System.out.println(getEmail_id());
String link="\"http://localhost:15403/Struts_ApplicationTest/change_Pwd.jsp?=\"";
body="\n<a href="+link+getEmail_id()+">Click here to reset password</a>";
// body= "\n<a href='http://localhost:15403/Struts_ApplicationTest/change_Pwd.jsp>Click here to reset password</a>";
SecurityManager s = new SecurityManager();
System.out.println("assdddssdsd" + s);
Session session = Session.getInstance(properties,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(em_from, em_password);
}
});
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(em_from));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(email_id));
message.setSubject(subject);
message.setDataHandler(new DataHandler(
new ByteArrayDataSource(body, "text/html")));
Transport.send(message);
} catch (Exception e) {
e.printStackTrace();
return "error";
}
return "sent";
}
使用此功能,我无法在通过电子邮件发送的链接中获取传递的变量名称。 提前谢谢。
答案 0 :(得分:0)
如果要设置锚标记的某些属性href
,则应使用单引号或双引号引用它。双引号需要通过Java转义,而不是单独引用。
String link="http://localhost:15403/Struts_ApplicationTest/change_Pwd.jsp?=";
body="\n<a href='"+link+getEmail_id()+"'>Click here to reset password</a>";