//LoginAction的提交处理函数:
public String post() throws Exception{
request = ServletActionContext.getRequest();
session=request.getSession();
String code=(String)session.getAttribute("code");
if(!getCheckcode().equals(code)){
outJs("验证码错误!","login_form.do");
return null;
}
int i=0;
if("".equals(user.getUsername())||"".equals(user.getPassword())){
outJs("用户名密码不能为空!","login_form.do");
fw= null;
}else{
i=new UserDao().checkUser(user.getPassword(), user.getUsername());
if(i==0){
outJs("用户名或密码错误,请确认后再填!","login_form.do");
fw= null;
}else{
user=new UserDao().getUser(i);
new Auth().save(user);
if(user.getPri()==1){
fw= "admin";
}else{
fw= "user";
}
}
}
return fw;
}
//输出信息的js并跳转:
private void outJs(String msg,String forword){
ActionContext ctx=ActionContext.getContext();
HttpServletResponse response=(HttpServletResponse)ctx.get(org.apache.struts2.StrutsStatics.HTTP_RESPONSE);
response.setContentType("text/html; charset=utf-8");
PrintWriter out=null;
try {
String str="<script type=\"text/javascript\" language=\"javascript\">";
out=response.getWriter();
str+="alert(\""+msg+"\");";
str+="window.location.href='"+forword+"'";
str+="</script>";
out.print(str);
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public String post() throws Exception{
request = ServletActionContext.getRequest();
session=request.getSession();
String code=(String)session.getAttribute("code");
if(!getCheckcode().equals(code)){
outJs("验证码错误!","login_form.do");
return null;
}
int i=0;
if("".equals(user.getUsername())||"".equals(user.getPassword())){
outJs("用户名密码不能为空!","login_form.do");
fw= null;
}else{
i=new UserDao().checkUser(user.getPassword(), user.getUsername());
if(i==0){
outJs("用户名或密码错误,请确认后再填!","login_form.do");
fw= null;
}else{
user=new UserDao().getUser(i);
new Auth().save(user);
if(user.getPri()==1){
fw= "admin";
}else{
fw= "user";
}
}
}
return fw;
}
//输出信息的js并跳转:
private void outJs(String msg,String forword){
ActionContext ctx=ActionContext.getContext();
HttpServletResponse response=(HttpServletResponse)ctx.get(org.apache.struts2.StrutsStatics.HTTP_RESPONSE);
response.setContentType("text/html; charset=utf-8");
PrintWriter out=null;
try {
String str="<script type=\"text/javascript\" language=\"javascript\">";
out=response.getWriter();
str+="alert(\""+msg+"\");";
str+="window.location.href='"+forword+"'";
str+="</script>";
out.print(str);
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}