?? logonaction.java
字號:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.yourcompany.struts.action;
import java.util.Properties;
import java.util.List;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.yourcompany.struts.Person;
import com.yourcompany.struts.UserManger;
import com.yourcompany.struts.form.LogonForm;
/**
* MyEclipse Struts
* Creation date: 10-04-2008
*
* XDoclet definition:
* @struts.action path="/logon" name="logonForm" input="/login/logon.jsp" scope="request" validate="true"
*/
public class LogonAction extends Action {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LogonForm logonForm = (LogonForm) form;
// TODO Auto-generated method stub
String name=logonForm.getName();
String pwd=logonForm.getPwd();
UserManger db=new UserManger();
/*return(mapping.findForward("sucess"));
**/
if(db.checkUser(name,pwd))
{
db=new UserManger();
List<Person> userlist = null;
userlist=db.list();
System.out.println(userlist.get(0).getName());
System.out.println(userlist.get(1).getName());
System.out.println(userlist.get(2).getName());
request.setAttribute("userList", userlist);
return(mapping.findForward("other"));
}
else
{
db.addUser(name, pwd);
//db.delUser(name);
return(mapping.findForward("fail"));
}
}
}/*//if(name==""&&pwd=="")
String toAddr = "laoliljw@163.com";
String subject = "Time over";
String body = "You have to return the books you borrowed";
//Here write your own email or get it from a parameter
String fromAddr = "laoliljw1985@163.com";
try {
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.163.com");
props.put("", arg1)
// Here we specify the SMTP server through
// which the mail should be delivered
Session session = Session.getDefaultInstance(props, null);
MimeMessage msg = new MimeMessage(session);
// Specify the From Address
msg.setFrom(new InternetAddress(fromAddr));
// Format the To Address
InternetAddress[] tos = InternetAddress.parse(toAddr);
// Specify the To Address
msg.setRecipients(Message.RecipientType.TO, tos);
// Specify the Subject
msg.setSubject(subject);
// Specify the Body
msg.setText(body);
/**
*If the smtp server needn't Validation of the from
*address you needn't write the following
*four sentences.You should write it like that:
********Transport.send(msg);********
Transport tr=session.getTransport("smtp");
tr.connect("smtp.163.com", "laoliljw", "score1985");
msg.saveChanges();
tr.sendMessage(msg,msg.getAllRecipients());
} catch (Exception e) {
e.printStackTrace();
}*/
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -