www.pudn.com > mail.rar > MailWebAction.java


package email; 
 
import java.net.Socket; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
import javax.servlet.http.HttpSession; 
 
import org.springframework.web.context.WebApplicationContext; 
import org.springframework.web.context.support.WebApplicationContextUtils; 
import org.springframework.web.servlet.ModelAndView; 
import org.springframework.web.servlet.mvc.multiaction.MultiActionController; 
import org.springframework.web.servlet.view.RedirectView; 
 
public class MailWebAction extends MultiActionController { 
	//將該判斷網絡是否連通的方法轉成AOP,網絡不連通不給予操作郵件收發系統。。。 
    public boolean isConnected(){ 
    	boolean isConnected = false ; 
    	try {//网络测试连接 
			Socket socket = new Socket("www.163.com",80); 
			if(socket.isConnected()){ 
				isConnected = true ; 
			} 
		} catch (Exception e) { 
			 
		} 
    	 
    	return isConnected; 
    } 
	public CheckMailInf getCheckMailInf(){ 
		WebApplicationContext context = 
			 WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()); 
		CheckMailInf checkLogin = (CheckMailInf)context.getBean("checkMailProxy"); 
		return checkLogin ; 
	} 
	public ModelAndView mailLoginCheck(HttpServletRequest req,HttpServletResponse res){ 
		//System.out.println("....Mail User Login Checking..."+req.getContextPath()); 
		 
		 
		CheckMailInf checkLogin = this.getCheckMailInf(); 
		 
		HttpSession session = null; 
		try { 
			session = checkLogin.validator(req, res); 
		} catch (Exception e) { 
			System.out.println("無法與郵件服器連接"); 
		} 
		 
		if(session == null){ 
			req.setAttribute("message","连接邮件服务器失败,请稍后再试."); 
			req.getSession().setAttribute("message","连接邮件服务器失败,请稍后再试;请检查用户名与密码是否正确."); 
			return new ModelAndView(new RedirectView(req.getContextPath()+"/mail/loginMail.jsp")); 
		    //return new ModelAndView("/vwasview/return.jsp"); 
		}else{ 
			return new ModelAndView(new RedirectView(req.getContextPath()+"/mail/mail.jsp")); 
		} 
	} 
	public ModelAndView mailSender(HttpServletRequest req,HttpServletResponse res){ 
		 
		CheckMailInf checkLogin = this.getCheckMailInf(); 
		 
		String message = checkLogin.sendMail(req, res) ; 
		System.out.println("send mail:"+message); 
		req.getSession().setAttribute("message",message); 
		return new ModelAndView(new RedirectView(req.getContextPath()+"/mail/mailSender.jsp")); 
		//return new ModelAndView(req.getContextPath()+"/mail/mail.jsp"); 
	} 
	public ModelAndView browerMyInbox(HttpServletRequest req,HttpServletResponse res){ 
		 
		CheckMailInf checkLogin = this.getCheckMailInf(); 
		HttpSession httpSession  = req.getSession(); 
		MyInboxCollection mc = null ; 
		//獲取郵件列表是否成功提示信息 
		String message = " "; 
		try { 
			httpSession.removeAttribute("myInbox"); 
			mc = checkLogin.obtainMyInboses((UserConfig)httpSession.getAttribute("userConfig")); 
		    httpSession.setAttribute("myInbox",mc); 
		    //System.out.println("获取成功:"+mc.getMailCount()+"   邮件总数:"+mc.getMyInbosex().size()); 
		} catch (Exception e) { 
			message = "与邮件服务器连接失败,未能成功获取你所需的邮件列表...."; 
			e.printStackTrace(); 
		} 
		req.setAttribute("message",message); 
		 
		//return new ModelAndView(new RedirectView(req.getContextPath()+"/mail/listFolder.jsp")); 
		return new ModelAndView(new RedirectView(req.getContextPath()+"/mail/myinbox.jsp")); 
	} 
	 
 
}