Java 为什么在MimeMessage的第50行显示一个bug 每当我试着编译这个servlet时,它总是显示一个错误 第50行:
从非最终变量消息中删除最终变量:Java 为什么在MimeMessage的第50行显示一个bug 每当我试着编译这个servlet时,它总是显示一个错误 第50行:,java,Java,从非最终变量消息中删除最终变量: 我通过使用message.setText而不是message.setContent解决了这个问题。它显示了什么bug?从非final变量中删除final,并在控制台上显示-INFO:至少有一个JAR被扫描了TLD,但没有包含TLD。为此记录器启用调试日志记录以获取已扫描的JAR的完整列表,但未找到TLD。在扫描过程中跳过不需要的JAR可以缩短启动时间和JSP编译时间。 package com.registration; import java.
我通过使用message.setText而不是message.setContent解决了这个问题。它显示了什么bug?从非final变量中删除final,并在控制台上显示-INFO:至少有一个JAR被扫描了TLD,但没有包含TLD。为此记录器启用调试日志记录以获取已扫描的JAR的完整列表,但未找到TLD。在扫描过程中跳过不需要的JAR可以缩短启动时间和JSP编译时间。
package com.registration;
import java.io.IOException;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@WebServlet("/Process")
public class Process extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession httpSession = request.getSession();
final String from = "//use ur own";
final String pass = "//use ur own";
final MimeMessage message;
String first_name = request.getParameter("first_name");
String last_name = request.getParameter("last_name");
String email = request.getParameter("email");
String password = request.getParameter("password");
httpSession.setAttribute("first_name", first_name);
httpSession.setAttribute("last_name", last_name);
httpSession.setAttribute("email", email);
httpSession.setAttribute("password", password);
int randomPin = (int) (Math.random() * Math.pow(10, 6));
httpSession.setAttribute("randomPin", randomPin);
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com"); // THIS IS THE SMTP SERVER SERVER ADDRESS
props.put("mail.smtp.port", "587"); // THIS IS THE PORT FOR THE SMTP SERVER
Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(from, pass); // THIS IS TO AUTHENTICATE YOUR GEMAIL ACCOUNT
}
});
try {
message = new MimeMessage(session);
message.setFrom(new InternetAddress("jskm.shop.co@gmail.com"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email));
message.setSubject("Your otp for registeration is"); // SETS THE SUBJECT FOR THE EMAIL
message.setContent(
"<h:body style=background-color:white;font-family:verdana; color:0000ee "
+ "Enter this OTP for your successfull registeration</br></br>" + "</body>",
"text/html; charset-utf-8");
Transport.send(message);
System.out.println("Email was sent successfully");
response.sendRedirect("../otp.jsp");
} catch (Exception e) {
}
}
}
MimeMessage message;