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

(4.1-4.7)拼团项目进度汇报

时间:2017-04-13 00:45:36      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:[]   out   div   parameter   patch   set   name   obj   ring   

1.任务安排

计划时间 计划任务 计划是否完成
3.22-3.29  管理员的增删改查 
3.29-4.5  编写活动模块
4.5-4.12 完善活动的增删改查   

2.下周计划完成内容

  完善活动的增删改查

3.本周实现功能

  • a.编写活动类
  • b.完善活动的servlet层代码
  • c.基本实现用户的增删改查

 

4.本周实现代码

  整合了仕庄的代码

  •   servlet类都放在action包里,用于存放增删改查操作
  •   bean包里放实体类
  •   dao包里放dao接口类

   技术分享

主要编写了EventthreadServlet类中的doPost()中的增删改查:

package pintuan.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import pintuan.bean.User;
import pintuan.db.DBConnection;

public class UserServlet extends HttpServlet {
    private DBConnection dbc=new DBConnection();
    private static final long serialVersionUID = 1L;
       
  
    public UserServlet() {
    }

    
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String action=request.getParameter("action");
        if(action.equals("query")){
            String sql="select * from pt_user";
            ResultSet rs=null;
            List<User> userList=new ArrayList<User>();
            try {
                rs = dbc.doQueryRS(sql,new Object[]{});
                
                while(rs.next())
                {
                    User user=new User();
                    user.setUserName(rs.getString("UserName"));
                    user.setUserID(rs.getString("UserID"));
                    user.setId(rs.getInt("id"));
                    user.setPassword(rs.getString("Password"));
                    user.setEmail(rs.getString("Email"));
                    user.setIsDelete(rs.getInt("isDelete"));
                    user.setIsApplied(rs.getInt("isApplied"));
                    user.setIsProfile(rs.getInt("isProfile"));
        
                    userList.add(user);
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }   
            
            HttpSession session=request.getSession();
            session.setAttribute("userList", userList);
            request.getRequestDispatcher("user_list.jsp").forward(request, response);
        }else if(action.equals("del"))
        {
            int id=Integer.parseInt(request.getParameter("id"));
            String sql="delete from pt_user where id=?";
            int res=0;
            try {
                res = dbc.doUpdate(sql,new Object[]{id});
            } catch (SQLException e) {
                e.printStackTrace();
            }
            if(res>0)
            {
                request.getRequestDispatcher("user?action=query").forward(request, response);
            }else
            {
                PrintWriter out=response.getWriter();
                out.print("删除失败");
                out.close();
            }
        }else if(action.equals("add"))
        {
            String UserID=request.getParameter("UserID");
            String UserName = request.getParameter("UserName");
            String Password = request.getParameter("Password");
            String email = request.getParameter("email");
            int isApplied = Integer.parseInt(request.getParameter("isApplied"));
            int isDelete = Integer.parseInt(request.getParameter("isDelete"));
            int isProfile = Integer.parseInt(request.getParameter("isProfile"));
    
            String sql="insert into pt_user(UserID,UserName,Password,email,isApplied,isDelete,isProfile) values(?,?,?,?,?,?,?)";
            int res=0;
            try {
                res = dbc.doUpdate(sql,new Object[]{UserID,UserName,Password,email,isApplied,isDelete,isProfile});
            } catch (SQLException e) {
                e.printStackTrace();
            }
            if(res>0)
            {
                request.getRequestDispatcher("user?action=query").forward(request, response);
            }else
            {
                PrintWriter out=response.getWriter();
                out.print("添加失败");
                out.close();
            }
            
        }else if(action.equals("edit"))
        {
            int id=Integer.parseInt(request.getParameter("id"));
            String sql="select * from pt_user where id=?";
            User user=null;
            try {
                ResultSet rs=dbc.doQueryRS(sql,new Object[]{id});
                if(rs.next())
                {
                    user = new User();
                    user.setUserID(rs.getString("UserID"));
                    user.setUserName(rs.getString("UserName"));
                    user.setPassword(rs.getString("Password"));
                    user.setIsApplied(rs.getInt("isApplied"));
                    user.setIsDelete(rs.getInt("isDelete"));
                    user.setIsProfile(rs.getInt("isProfile"));
                    user.setId(rs.getInt("id"));
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
            HttpSession session=request.getSession();
            session.setAttribute("user", user);
            request.getRequestDispatcher("edit_user.jsp").forward(request, response);
            
        }else if(action.equals("update"))
        {
            int id=Integer.parseInt(request.getParameter("id"));
            String UserID=request.getParameter("UserID");
            String UserName = request.getParameter("UserName");
            String Password = request.getParameter("Password");
            String email = request.getParameter("email");
            int isApplied = Integer.parseInt(request.getParameter("isApplied"));
            int isDelete = Integer.parseInt(request.getParameter("isDelete"));
            int isProfile = Integer.parseInt(request.getParameter("isProfile"));
    
            String sql="update pt_user set "
                    + "UserID=?,UserName=?,Password=?,email=?,"
                    + "isApplied=?,isDelete=?,isProfile = ? where id=?";
            int res=0;
            try {
                res = dbc.doUpdate(sql,new Object[]{UserID,UserName,Password,email,isApplied,isDelete,isProfile,id});
            } catch (SQLException e) {
                e.printStackTrace();
            }
            if(res>0)
            {
                request.getRequestDispatcher("user?action=query").forward(request, response);
            }else
            {
                PrintWriter out=response.getWriter();
                out.print("更新失败");
                out.close();
            }
        }else if(action.equals("register"))
        {
            String UserID=request.getParameter("UserID");
            String UserName = request.getParameter("UserName");
            String Password = request.getParameter("Password");
            String email = request.getParameter("email");
            int isApplied = Integer.parseInt(request.getParameter("isApplied"));
            int isDelete = Integer.parseInt(request.getParameter("isDelete"));
            int isProfile = Integer.parseInt(request.getParameter("isProfile"));
    
            String sql="insert into pt_user(UserID,UserName,Password,email,isApplied,isDelete,isProfile) values(?,?,?,?,?,?,?)";
            int res=0;
            try {
                res = dbc.doUpdate(sql,new Object[]{UserID,UserName,Password,email,isApplied,isDelete,isProfile});
            } catch (SQLException e) {
                e.printStackTrace();
            }
            if(res>0)
            {
                request.getRequestDispatcher("register_result_test.jsp").forward(request, response);
            }else
            {
                PrintWriter out=response.getWriter();
                out.print("添加失败");
                out.close();
            }
            
        }
        else
        {
            
        }
    }

}

 

5.本周代码实现截图

 

 

 

 

 

 

6.本周碰到问题及解决方法

 

7.本周小结

(4.1-4.7)拼团项目进度汇报

标签:[]   out   div   parameter   patch   set   name   obj   ring   

原文地址:http://www.cnblogs.com/gxt-smart/p/6701899.html

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