码迷,mamicode.com
首页 > 其他好文 > 详细

收藏模块

时间:2015-06-29 06:22:11      阅读:72      评论:0      收藏:0      [点我收藏+]

标签:

收藏模块功能的实现

1.在个人登陆状态下,在热门关注里选择喜欢的问题,点击收藏便可收藏该问题

技术分享

代码:

 <body>
  
        <% 
          String topic=new String(request.getParameter("topic").getBytes("ISO-8859-1"),"UTF-8");
          String author=new String(request.getParameter("author").getBytes("ISO-8859-1"),"UTF-8"); 
          String classify=new String(request.getParameter("classify").getBytes("ISO-8859-1"),"UTF-8");             
          String userName =(String)session.getAttribute("userName"); 
          if(userName==null) {
                String msg="请先登陆账户!";
                int type=JOptionPane.YES_NO_CANCEL_OPTION;
                String title="信息提示";
                JOptionPane.showMessageDialog(null, msg, title, type);
                response.sendRedirect("hotquestion.jsp");
            }else {      
          Connection con=null;
          Statement stmt=null;
          Class.forName("com.mysql.jdbc.Driver");
          String url="jdbc:mysql://localhost:3306/learning?useUnicode=true&characterEncoding=gbk";
          con=DriverManager.getConnection(url,"root","root");
          stmt=con.createStatement();
          String sql0="INSERT INTO `shoucang` VALUES (‘"+classify+"‘, ‘"+author+"‘, ‘"+topic+"‘,‘"+userName+"‘);";
          stmt.executeUpdate(sql0);
          response.sendRedirect("hotquestion.jsp");            
          stmt.close();
          con.close();
          }
          %>
  </body>

  2.在我的收藏里可以查看个人收藏

技术分享

 <body>
  
        <%
          String userName =(String)session.getAttribute("userName");
            if(userName==null) {
                String msg="请先登陆账户!";
                int type=JOptionPane.YES_NO_CANCEL_OPTION;
                String title="信息提示";
                JOptionPane.showMessageDialog(null, msg, title, type);
                response.sendRedirect("tishi.jsp");
            }else {
          Connection con=null;
          Statement stmt=null;
          ResultSet rs=null;
          String author;
          String topic;
          int i=0;
          Class.forName("com.mysql.jdbc.Driver");
          String url="jdbc:mysql://localhost:3306/learning?useUnicode=true&characterEncoding=gbk";
          con=DriverManager.getConnection(url,"root","root");
          stmt=con.createStatement();
          String query="select distinct * from `shoucang` where userName=‘"+userName+"‘";
          rs=stmt.executeQuery(query);
          %>
    <table align="center" width="100%" border="1">
        <tr background="#22dcff" >
            <th>编号</th>
            <th>类型</th>
            <th>主题</th>
            <th>操作</th>
        </tr>
          <%
          while(rs.next()){  
          author=rs.getString("author");
          topic=rs.getString("topic"); 
          i++; 
           %>
          <tr height="40" >
              <td align="center"><%=i %></td>
              <td align="center"><%=rs.getString("classify") %></td>
              <td align="center"><a href="dealing/response.jsp?author=<%=author%>&topic=<%=topic%>"><%=topic%></a></td>
              <td align="center"><a href="dealing/deleteshouc.jsp?author=<%=author%>&topic=<%=topic%>">删除</a></td>
          </tr>
          <%
            }
            }
           %>
     </table>
  </body>

  3.个人收藏删除

技术分享

代码:

      <body>
           <%   String topic=new String(request.getParameter("topic").getBytes("ISO-8859-1"),"UTF-8");
                String author=new String(request.getParameter("author").getBytes("ISO-8859-1"),"UTF-8");      
                Connection con=null;
                Statement stmt=null;
                Class.forName("com.mysql.jdbc.Driver");
                /*3306为端口号,student为数据库名,url后面加的?useUnicode=true&characterEncoding=gbk,是为了处理向数据库中添加数据时出现乱码的问题。*/
                String url="jdbc:mysql://localhost:3306/learning?useUnicode=true&characterEncoding=gbk";
                con=DriverManager.getConnection(url,"root","root");
                stmt=con.createStatement();
                String sql2="DELETE FROM `shoucang` WHERE author=‘"+author+"‘ AND topic=‘"+topic+"‘";
                stmt.executeUpdate(sql2);
                String msg="删除成功!";
                int type=JOptionPane.YES_NO_CANCEL_OPTION;
                String title="信息提示";
                JOptionPane.showMessageDialog(null, msg, title, type);
                response.sendRedirect("mysave.jsp");
                stmt.close();
                con.close();
            %>
    </body>

  

收藏模块

标签:

原文地址:http://www.cnblogs.com/fellerlong/p/4606443.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!