📄 loginaction.java
字号:
package ezmail;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.Folder;
public class LoginAction implements Action {
public LoginAction() {
}
/**
* Performs the following steps during login
* <ol>
* <li>Reads form data for: pop3server, user, and password</li>
* <li>Configure mail session</li>
* <li>Constructs a UserInfo object and place in the HttpSession</li>
* <li>Set the LOGGED_IN flag to true</li>
* </ol>
*
* The data is then placed in the user's session. The attribute is named
* <code>Constants.DATA</code>
*/
public void perform(ServletContext servletContext,
HttpServletRequest request,
HttpServletResponse response) throws ActionException {
try {
HttpSession theHttpSession = request.getSession();
// retrieve data from login form and servlet context
String pop3host = request.getParameter("pop3host");
String user = request.getParameter("user");
String password = request.getParameter("password");
String emailAddress = request.getParameter("email_address");
String smtphost = servletContext.getInitParameter("smtphost");
// Configure the mail session
System.out.println("Configuring mail session");
java.util.Properties props = new java.util.Properties();
props.put("mail.smtp.host", smtphost);
props.put("mail.pop3.host", pop3host);
Session mailSession = Session.getInstance(props, null);
System.out.println("Configuring mail session....complete!");
// create a UserInfo object
UserInfo info = new UserInfo(pop3host, user, password, emailAddress);
// now let's add user data to the session
theHttpSession.setAttribute(Constants.MAIL_SESSION, mailSession);
theHttpSession.setAttribute(Constants.USER_INFO, info);
theHttpSession.setAttribute(Constants.LOGIN_STATUS, new Boolean(true));
}
catch (Exception exc) {
exc.printStackTrace();
throw new ActionException(exc.getMessage());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -