?? logaction.java
字號:
/*
* 創建日期 2005-12-7
*
* TODO 要更改此生成的文件的模板,請轉至
* 窗口 - 首選項 - Java - 代碼樣式 - 代碼模板
*/
package bit.jeffy.action;
import java.sql.ResultSet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import bit.jeffy.personal.UserBean;
import bit.jeffy.db.DataStore;
/**
* @author jeffy
*
* TODO 要更改此生成的類型注釋的模板,請轉至
* 窗口 - 首選項 - Java - 代碼樣式 - 代碼模板
*/
public class LogAction extends Action {
/* (非 Javadoc)
* @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public ActionForward execute(ActionMapping map, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
// TODO 自動生成方法存根
ActionErrors errors = new ActionErrors();
HttpSession s = request.getSession();
String username = null;
String password = null;
String s_user = null;
username = (String)((UserBean)form).getUserName();
password = (String)((UserBean)form).getPassWord();
username = new String(username.getBytes("ISO-8859-1"),"GB2312");
password = new String(password.getBytes("ISO-8859-1"),"GB2312");
DataStore db = DataStore.getInstance();
if( db == null ){
errors.add("fail_1",new ActionError("log.action.a"));
saveErrors(request,errors);
return (map.findForward("logerror"));
}
ResultSet st = null;
String sql = "select * from Client where ZH='"+username+
"' and UPASSWORD='"+password+"'";
st = db.read(sql);
if( st != null && st.next()){
s_user = (String)s.getAttribute("current_user");
if( s_user == null ){
s.setAttribute("current_user",username);
return (map.findForward("login"));
}else{
//踢掉當前用戶
s.removeAttribute("current_user");
s.setAttribute("current_user",username);
return (map.findForward("login"));
}
}else{
errors.add("fail_2",new ActionError("Log.error.c"));
saveErrors(request,errors);
return (map.findForward("logerror"));
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -