www.pudn.com > JMail4Email.rar > 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 
	 *  
    *
  1. Reads form data for: pop3server, user, and password
  2. *
  3. Configure mail session
  4. *
  5. Constructs a UserInfo object and place in the HttpSession
  6. *
  7. Set the LOGGED_IN flag to true
  8. *
* * The data is then placed in the user's session. The attribute is named * Constants.DATA */ 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()); } } }