日期:2014-05-17 浏览次数:20703 次
import java.io.ByteArrayInputStream; import Web.RandomNumUtil; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; public class RandomAction extends ActionSupport{ /** * */ private static final long serialVersionUID = 1L; private ByteArrayInputStream inputStream; public String execute() throws Exception{ RandomNumUtil rdnu=RandomNumUtil.Instance(); this.setInputStream(rdnu.getImage()); ActionContext.getContext().getSession().put("random", rdnu.getString()); System.out.println("生成验证码:"+rdnu.getString()); System.out.println("获得验证码:"+ActionContext.getContext().getSession().get("random")); return SUCCESS; } public void setInputStream(ByteArrayInputStream inputStream) { this.inputStream = inputStream; } public ByteArrayInputStream getInputStream() { return inputStream; } }
import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.Random; import javax.imageio.ImageIO; import javax.imageio.stream.ImageOutputStream; public class RandomNumUtil { privateprovider="java:MSG">
import com.ccniit.service.UserManager;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
*
*/
private String username;
private String password1;
private String vercode;
public String getVercode() {
return vercode;
}
public void setVercode(String vercode) {
this.vercode = vercode;
}
private String msg;
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
protected UserManager mgr;
public void setMgr(UserManager mgr) {
this.mgr = mgr;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword1() {
return password1;
}
public void setPassword1(String password1) {
this.password1 = password1;
}
public String showReg() throws Exception {
return SUCCESS;
}
public String login() throws Exception {
String ver2=(String) ActionContext.getContext().getSession().get("random");
System.out.println("random:" + ver2);
System.out.println("用户输入:" + getVercode());
if (getVercode().equals(getVercode())) {
if (mgr.login(getUsername(), getPassword1()) > 0)