4.1-4.7课题(拼团系统)进度汇报

https://coding.net/u/shizhuangde/p/PinTuan/git

1.任务安排

计划时间 计划任务 计划是否完成
3.22-3.29  将活动模块用Servlet方法   是
3.29-4.5  编写登陆模块  否
4.1-4.7  编写用户注册模块   是

2.下周计划完成内容

  用户完善个人资料功能

3.本周实现功能

  a.编写用户类,实现用户的增删改查

  b.实现用户的注册,并且用上其他成员编写的界面代码

4.本周实现代码

  整个项目的结构:

  -servlet类都放在action包里

  -bean包里放实体类

  -dao包里放dao接口类

       

主要编写了UserServlet类中的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
        {
            
        }
    }

}
View Code

 

5.本周代码实现截图

注册界面:

 

 

尝试注册用户:

 

输入错误邮箱地址时会提示。

正确创建后,到数据库查看确实注册成功:

 

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

  在参考别的实践例子之后,大多数程序是注册时填写的资料比较少,然后有个完善资料的功能,其他团队成员编写的程序在用户注册这一块,虽然可以选择个人还是企业类型,但是之后的逻辑判断并没有将二者分开,所以另外做一个完善资料的功能,不仅在注册的时候让用户觉得更轻便(没有太多的资料要填),而且对区分企业还是个人用户还是由一定好处吧。这一块小组成员还需要开会讨论一下。另外就是课题要求的基于微信平台的开发,在做登陆这一块的时候觉得其实就微信授权登陆,不仅完成登陆还完成了注册,那么我上面写的这部分的功能几乎没什么用了。对于接下来要做的事情有点迷茫。

7.本周小结

  还有太多东西需要去学了,感觉方向有点不对了。

posted @ 2017-04-12 22:49  是装的  阅读(292)  评论(1编辑  收藏  举报