2014-07-16 3 views
0

자바 메일 API를 사용하여 비밀번호 재설정 링크를 보내도록 href 태그에 동적 값 (액션 클래스)을 갖는 클래스 변수를 추가하는 방법.Struts에서 비밀번호 구현 재설정

내 전송 방법은 다음과 같습니다이 사용

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

문자열이므로 다른 문자열 값처럼 추가하십시오. –

+5

이 질문의 태깅에 대해 두 사람이 토론하고 싶다면 Meta로 가져 가십시오. http://meta.stackoverflow.com/questions/265943/i-need-clarification-on-tagging-questions-with-technologies –

답변

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>";