我正在使用JSP页面从我的动作类
作为电子邮件模板发送即aaa.jsp
接受来自用户的email_id,然后重定向到Mail操作,以便向用户发送hashcode
,然后重定向到yyy.jsp
以输入发送到hashcode
的{{1}}由用户提供。我使用emil_id
作为电子邮件模板。
我的xxx.jsp
是
xxx.jsp
我有一个动作类,它向用户发送一封电子邮件,其中包含用于注册目的的身份验证代码。
<html>
<head>
</head>
<body>
<s:property value="hashcode"/>
</body>
</html>
用于检查此邮件是否已注册,并将checkAndMail
页面转换为字符串
xxx.jsp
我从public String checkAndMail() throws Exception{
this.hashcode="9048075352";//getters and setters are used for hashxode and is of type String
/***********
code for searching whether the email is registered already
************/
HttpServletResponse response = ServletActionContext.getResponse();
HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(response) {
private final StringWriter sw = new StringWriter();
@Override
public PrintWriter getWriter() throws IOException {
return new PrintWriter(sw);
}
@Override
public String toString() {
return sw.toString();
}
};
setHashcode(hashcode);
request.getRequestDispatcher("aa/bb/xxx.jsp").include(request,
responseWrapper);
String result1 = responseWrapper.toString();
sendMailNew("christinchacko@gmail.com", result1,"AssignMail" );
TARGET = "success";
}
致电sendMailNew
发送邮件。我的checkAndMail
方法用于发送邮件
sendMailNew
我的问题是如何将值{(此参数为public synchronized void sendMailNew(String mailTo,String Content,String type) throws Exception
{
String TEXT="";
Properties props = new Properties();
props.put("mail.smtp.host", HOST);
props.put("mail.smtp.user", USER);
props.put("mail.smtp.auth", AUTH);
props.put("mail.smtp.starttls.enable", STARTTLS);
props.put("mail.smtp.debug", DEBUG);
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.socketFactory.fallback", "false");
try {
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);
MimeMessage message = new MimeMessage(session);
//message.setText(TEXT);
if(type.equals("AssignMail"))
{
message.setContent(Content, "text/html");
}
message.setSubject(SUBJECT);
message.setFrom(new InternetAddress(FROM));
message.addRecipients(RecipientType.TO, mailTo);
message.saveChanges();
Transport transport = session.getTransport("smtp");
transport.connect(HOST, USER, PASSWORD);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
} catch (Exception e) {
throw new Exception("Exception in Mail.sendMail" + e.getMessage());
}
}
)从hashcode
传递到checkAdnMail
此操作类被重定向到xxx.jsp
,用于输入应发送到用户电子邮件地址的yyy.jsp
。
参考:Struts2 - How can I get the result of a JSP page as a string in an action class (for emails)
答案 0 :(得分:1)
您可以使用请求属性传递值。例如
request.setAttribute("hashcode", hashcode);
然后在JSP中,您必须在struts标记中引用请求对象,或者只使用JSP EL
<s:property value="#request.hashcode"/>
或
${hashcode}
最后一个值未转义,如果代码中包含错误的字符,请务必小心。