java换肤改变页面肤色

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.Cookie;
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.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class ChangeColorAction extends Action{
 

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, Exception
    {
         response.setCharacterEncoding("UTF-8");
         HttpSession sess = request.getSession(true);
         PrintWriter out=null;
          try{
     out= response.getWriter();
    } catch(Exception e){e.printStackTrace();}
   String color = request.getParameter("color");
   
        //读入cookie
        Cookie cookies[]=request.getCookies(); // 将适用目录下所有Cookie读入并存入cookies数组中
        Cookie sCookie=null;
        String sname=null;
        String name=null;
        if(cookies==null) {// 如果没有任何cookie
          System.out.println("none any cookie");
          name="";
          }
        else
        {
          System.out.println(cookies.length + "<br>");
          for(int i=0;i<cookies.length; i++) // 循环列出所有可用的Cookie
          {
            sCookie=cookies[i];
            sname=sCookie.getName();
            if("OAcolor".equals(sname))
            name = sCookie.getValue();
            System.out.println(sname + "->" + name + "<br>"+sCookie.getPath());
          }
        }
        //写入cookie
         Cookie _cookie=new Cookie("OAcolor", color);
            _cookie.setMaxAge(60*60*24*30*12); // 设置Cookie的存活时间为30分钟
            _cookie.setPath("/");
            response.addCookie(_cookie); // 写入客户端硬盘
            System.out.println("写Cookie完成");
            sess.setAttribute("color", name);
        return null;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值