首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

cookie的Struts2兑现

2012-08-21 
cookie的Struts2实现Cookie c new Cookie(username, username)c.setMaxAge(60 * 60)ServletActionCo

cookie的Struts2实现

Cookie c = new Cookie("username", username);c.setMaxAge(60 * 60);ServletActionContext.getResponse().addCookie(c);

<span name="code">package com.baitw.struts.action;import javax.servlet.http.Cookie;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts2.ServletActionContext;import org.apache.struts2.interceptor.ServletRequestAware;import org.apache.struts2.interceptor.ServletResponseAware;import com.baitw.dao.UserDao;import com.opensymphony.xwork2.Action;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;/** *  * 管理员登陆 *  * */public class LoginAction extends ActionSupport{private String username;private String password;private String CheckingCode;public UserDao userDao;public String getCheckingCode() {return CheckingCode;}public void setCheckingCode(String checkingCode) {CheckingCode = checkingCode;}public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public void setUserDao(UserDao userDao) {this.userDao = userDao;}@Overridepublic String execute() throws Exception {// TODO Auto-generated method stubActionContext ctx=ActionContext.getContext();if(!CheckingCode.equals(ctx.getSession().get("rand"))){ctx.put("Msg", "验证码有误!");return "error";}Cookie c = new Cookie("username", username);c.setMaxAge(60 * 60);ServletActionContext.getResponse().addCookie(c);return userDao.Login(username, password);}}

热点排行