<%
  //String user=request.getParameter("");
  int i=0;
  Cookie MyCookie=new Cookie(String.valueOf(i),java.net.URLEncoder.encode("竞技场版主"));
  MyCookie.setMaxAge(60);
  response.addCookie(MyCookie);
  i++;
  MyCookie=new Cookie(String.valueOf(i),java.net.URLEncoder.encode("竞技场版主"));
  MyCookie.setMaxAge(60);
  response.addCookie(MyCookie);
  i++;
  MyCookie=new Cookie(String.valueOf(i),java.net.URLEncoder.encode("竞技场版主"));
  MyCookie.setMaxAge(60);
  response.addCookie(MyCookie);
%>
<%
  Cookie[] cookies=request.getCookies();
  if(cookies!=null){
    for(int i=0;i<cookies.length;i++){
      %><h1>名字<%=cookies[i].getName()%>值<%=java.net.URLDecoder.decode(cookies[i].getValue())%><%
    }
  }
%>
报错:" jsp2.jsp" : 我在_jspService (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)已经被定义
是什么意思啊!

解决方案 »

  1.   

    把整个jsp贴出来看看是不是重复定义了
      

  2.   


    在登陆界面如下代码!
    user为用户的名字从登陆界面提交过来的.
    若用户名存在就判断用户选中的保存期限 -1关闭浏览器就失效,1保存一天,7为一个星期,否则就一个月
    <%
     if(cookieDate!=null){
             Cookie mycookie=null;
             if(cookieDate.equals("-1")){
               mycookie=new Cookie("userName",java.net.URLEncoder.encode(user));
               mycookie.setMaxAge(-1);
               response.addCookie(mycookie);
               System.out.println(cookieDate);
             }
             else if(cookieDate.equals("1")){
               mycookie=new Cookie("userName",java.net.URLEncoder.encode(user));
               mycookie.setMaxAge(60*60*24);
               response.addCookie(mycookie);
               System.out.println(cookieDate);
              }
              else if(cookieDate.equals("7")){
               mycookie=new Cookie("userName",java.net.URLEncoder.encode(user));
               mycookie.setMaxAge((60*60*24)*7);
               response.addCookie(mycookie);
               System.out.println(cookieDate);
             }
             else {
               mycookie=new Cookie("userName",java.net.URLEncoder.encode(user));
               mycookie.setMaxAge(60*60*24*7*4);
               response.addCookie(mycookie);
               System.out.println(cookieDate);
             }
          }
    %>
    然后在主界面一下代码!
    <%
        String Points=null;
        String name=null;
        Cookie []cookie=request.getCookies();
        if(null!=cookie){
          for (int i = 0; i < cookie.length; i++) {
            System.out.println(cookie[i].getName());
            if(cookie[i].getName().equals("userName")){
              name=java.net.URLDecoder.decode(cookie[i].getValue());
              Points=data.reuurnPoints("select Points from Users where UserName='"+name+"'");
              session.setAttribute("Points",Points);
            }
          }
        }
    %>
     <%
        if(cookie!=null){
             if(null!=name){
               %><table width=95% align="center" style=color:#000000 width=100%    cellspacing=0                     
                <tr bgcolor="#93A0B7">
                 <td valign=middle ><FONT COLOR="#000000"> >>
                   欢迎您,<b><%=name%></b>  &nbsp;积分:<font color=red><%=Points%></font>  &nbsp;
                   <a href=denglu.jsp><FONT COLOR=#000000>重登陆</FONT></a>
                   | <a href=updatemy.jsp><FONT COLOR=#000000>更改信息</FONT></a>
                   | <a href="usersms.jsp?action=inbox" ><FONT COLOR=#000000>短消息</FONT></a>
                   | <a href=toplist.jsp?orders=1 ><FONT COLOR=#000000>发贴排行</FONT></a>
                   | <a href=query.jsp?forumID=0><FONT COLOR=#000000>搜索</FONT></a>
                   | <a href=help.jsp><FONT COLOR=#000000>帮助</FONT></a>
                   | <a href=logout.jsp><FONT COLOR=#000000>退出</FONT></a>
                 </td>
                 <td valign=middle align=right><FONT COLOR=#000000><a href="">魔兽世界</a>  &nbsp;<a href=''>
                   <img src=images/gohome.gif border=0></a></FONT>
                 </td>
               </tr>
             </table><%
            }else{%>
              <tr>
               <td><table style=color:#000000 width=100% cellspacing=0 cellpadding=4 border=0 >
               <tr bgcolor="#93A0B7">
             <td valign=middle ><FONT COLOR="#000000">>>
               欢迎您,<a href="denglu.jsp"><FONT COLOR=#000000>请先登录</FONT></a>
               | <a href="reg.jsp"><FONT COLOR=#000000>注册</FONT></a>
               | <a href=""><FONT COLOR=#000000>发贴排行</FONT></a>
               | <a href=""><FONT COLOR=#000000>搜索</FONT></a>
               | <a href=""><FONT COLOR=#000000>帮助</FONT></a>
               | <a href=""><FONT COLOR=#000000>退出</FONT></a>
             </td>
             <td valign=middle align=right><FONT COLOR=#000000><a href="">磨兽世界</a>&nbsp;
               <a href=""><img alt="" src="images/gohome.gif" border="0" /></a>
             </FONT></td>
           </tr>
         </table>
         <%}
    }else{%>
       <tr>
         <td><table style=color:#000000 width=100% cellspacing=0 cellpadding=4 border=0 >
           <tr bgcolor="#93A0B7">
             <td valign=middle ><FONT COLOR="#000000">>>
               欢迎您,<a href="denglu.jsp"><FONT COLOR=#000000>请先登录</FONT></a>
               | <a href="reg.jsp"><FONT COLOR=#000000>注册</FONT></a>
               | <a href=""><FONT COLOR=#000000>发贴排行</FONT></a>
               | <a href=""><FONT COLOR=#000000>搜索</FONT></a>
               | <a href=""><FONT COLOR=#000000>帮助</FONT></a>
               | <a href=""><FONT COLOR=#000000>退出</FONT></a>
             </td>
             <td valign=middle align=right><FONT COLOR=#000000><a href="">磨兽世界</a>&nbsp;
               <a href=""><img alt="" src="images/gohome.gif" border="0" /></a>
             </FONT></td>
           </tr>
         </table>
    <%}%>cellspacing=0
    若用户选择(保存一天)当浏览器被关闭时在打开用户名和积分依然存在!
    希望对大家有帮助!
    谢谢