📄 caaction.java
字号:
/*
* LogAction.java
*
* Created on 2008年2月21日, 下午2:39
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package com.myapp.struts;
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 com.myapp.struts.CABean;
import com.myapp.struts.DataStore;
/**
*
* @author Administrator
*/
public class CAAction extends Action{
/** Creates a new instance of LogAction */
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ActionErrors errors=new ActionErrors();
String username=null;
String userpsw=null;
HttpSession s=request.getSession();
String s_ca=null;
username=(String)((CABean)form).getUserName();
userpsw=(String)((CABean)form).getUserPsw();
//处理字符格式
username=new String(username.getBytes("ISO-8859-1"),"GB2312");
userpsw=new String(userpsw.getBytes("ISO-8859-1"),"GB2312");
DataStore db=DataStore.getInstance();
if(db==null){
errors.add("fail_1",new ActionError("实例为空!"));
return mapping.findForward("CAlog_error"); //返回登陆失败页面
}
ResultSet st=null;
String sql="select * from Cainfo where CAName='"+username+"' and CAPass='"+userpsw+"'";
st=db.read(sql);
if(st!=null && st.next()){
s_ca=(String)s.getAttribute("current_ca");
if(s_ca==null){
s.setAttribute("current_ca",username);
return mapping.findForward("CAlogin");
}else{
s.removeAttribute("current_ca");
s.setAttribute("current_ca",username);
return mapping.findForward("CAlogin");
}
}else{
errors.add("fail_1",new ActionError("对不起,该用户不存在!"));
return mapping.findForward("CAlog_error");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -