📄
字号:
范例CookieApply_end.jsp源代码:
001 <%@ page contentType="text/html; charset=GB2312"%>
002 <%
003 boolean is_cpt=true;
004 boolean is_phy=true;
005 boolean is_chem=true;
006 String User_Cpt,User_Phy,User_Chem;
007 //取得用户喜欢的主页风格
008 String R_Style = request.getParameter("R_Style");
009 //下面取得用户定购的书籍
010 //并算出各类书目的多少
011 //为以后根据定购不同类型的书籍得到用户的兴趣
012 int cpt=0;
013 int phy=0;
014 int chem=0;
015 int int_user_cpt=0;
016 int int_user_phy=0;
017 int int_user_chem=0;
018 String cpt1 = request.getParameter("cpt1");
019 if(cpt1!=null) cpt+=1;
020 String cpt2 = request.getParameter("cpt2");
021 if(cpt2!=null) cpt+=1;
022 String cpt3 = request.getParameter("cpt3");
023 if(cpt3!=null) cpt+=1;
024 String phy1 = request.getParameter("phy1");
025 if(phy1!=null) phy+=1;
026 String phy2 = request.getParameter("phy2");
027 if(phy2!=null) phy+=1;
028 String phy3 = request.getParameter("phy3");
029 if(phy3!=null) phy+=1;
030 String chem1 = request.getParameter("chem1");
031 if(chem1!=null) chem+=1;
032 String chem2 = request.getParameter("chem2");
033 if(chem2!=null) chem+=1;
034 String chem3 = request.getParameter("chem3");
035 if(chem3!=null) chem+=1;
036 String chem4 = request.getParameter("chem4");
037 if(chem4!=null) chem+=1;
038 //再把以前的书目数量从Cookies中读取出来
039 Cookie[] array_cookie = request.getCookies();
040 int array_len=array_cookie.length;
041 if(array_len!=0)
042 {
043 for(int i=0;i<array_len;i++)
044 {
045 //判定Cookie变量中保存的数据名字是否与需要的数据名字一致
046 if(array_cookie[i].getName().equals("user_cpt"))
047 {
048 User_Cpt=array_cookie[i].getValue();
049 int_user_cpt=Integer.parseInt(User_Cpt)+cpt;
050 //再的转成字符串型存入
051 User_Cpt=Integer.toString(int_user_cpt);
052 Cookie cookie_usercpt = new Cookie("user_cpt",User_Cpt);
053 cookie_usercpt.setMaxAge(604800);
054 response.addCookie(cookie_usercpt);
055 is_cpt=false;
056 }
057 if(array_cookie[i].getName().equals("user_phy"))
058 {
059 User_Phy=array_cookie[i].getValue();
060 int_user_phy=Integer.parseInt(User_Phy)+phy;
061 //再的转成字符串型存入
062 User_Phy=Integer.toString(int_user_phy);
063 Cookie cookie_userphy = new Cookie("user_phy",User_Phy);
064 cookie_userphy.setMaxAge(604800);
065 response.addCookie(cookie_userphy);
066 is_phy=false;
067 }
068 if(array_cookie[i].getName().equals("user_chem"))
069 {
070 User_Chem=array_cookie[i].getValue();
071 int_user_chem=Integer.parseInt(User_Chem)+chem;
072 //再的转成字符串型存入
073 User_Chem=Integer.toString(int_user_chem);
074 Cookie cookie_userchem = new Cookie("user_chem",User_Chem);
075 cookie_userchem.setMaxAge(604800);
076 response.addCookie(cookie_userchem);
077 is_chem=false;
078 }
079 }
080 }
081 if(is_cpt)
082 {
083 int_user_cpt=cpt;
084 User_Cpt=Integer.toString(int_user_cpt);
085 Cookie cookie_usercpt = new Cookie("user_cpt",User_Cpt);
086 cookie_usercpt.setMaxAge(604800);
087 response.addCookie(cookie_usercpt);
088 }
089 if(is_cpt)
090 {
091 int_user_phy=phy;
092 User_Phy=Integer.toString(int_user_phy);
093 Cookie cookie_userphy = new Cookie("user_phy",User_Phy);
094 cookie_userphy.setMaxAge(604800);
095 response.addCookie(cookie_userphy);
096 }
097 if(is_cpt)
098 {
099 int_user_chem=chem;
100 User_Chem=Integer.toString(int_user_chem);
101 Cookie cookie_userchem = new Cookie("user_chem",User_Chem);
102 cookie_userchem.setMaxAge(604800);
103 response.addCookie(cookie_userchem);
104 }
105 //如果用户更改了主页风格,要进行Cookie更新
106 if(R_Style!=null)
107 {
108 Cookie cookie_style = new Cookie("user_webstyle",R_Style);
109 cookie_style.setMaxAge(604800);
110 response.addCookie(cookie_style);
111 }
112 //最后对各类型的书籍数量进行排序,得出最大者为用户的兴趣所在
113 if(((int_user_cpt-int_user_phy)>=0)&&
114 ((int_user_cpt-int_user_chem)>=0))
115 {
116 Cookie cookie_likeaspact = new Cookie("user_likeaspact","1");
117 cookie_likeaspact.setMaxAge(604800);
118 response.addCookie(cookie_likeaspact);
119 }
120 if(((int_user_phy-int_user_cpt)>=0)&&
121 ((int_user_phy-int_user_chem)>=0))
122 {
123 Cookie cookie_likeaspact = new Cookie("user_likeaspact","2");
124 cookie_likeaspact.setMaxAge(604800);
125 response.addCookie(cookie_likeaspact);
126 }
127 if(((int_user_chem-int_user_cpt)>=0)&&
128 ((int_user_chem-int_user_phy)>=0))
129 {
130 Cookie cookie_likeaspact = new Cookie("user_likeaspact","3");
131 cookie_likeaspact.setMaxAge(604800);
132 response.addCookie(cookie_likeaspact);
133 }
134 response.sendRedirect("CookieApply_default.jsp");
135 %>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -