net网站开发的步骤txt,什么是网络营销?它包括了哪些主要环节?,网站建设技术思维导图,番禺做网站600元实现对部门信息的分类管理#xff0c;对不同部门人员的管理#xff08;增删改查#xff09;#xff0c;新用户的注册和登陆等
功能分析#xff1a;
实现用户的登陆实现用户的注册#xff08;注册不同的部门和职位#xff09;登陆之后会显示所有员工和经理的信息实现对…实现对部门信息的分类管理对不同部门人员的管理增删改查新用户的注册和登陆等
功能分析
实现用户的登陆实现用户的注册注册不同的部门和职位登陆之后会显示所有员工和经理的信息实现对这些信息的删除和更新操作
下面看一下效果图吧
登陆页面 注册页面 登陆之后页面 点击删除ID为10之后的页面 点击更新之后的页面
这个系统一共有两大步
1 . 数据库 2 . 后台功能的实现
下面我们将实现这两大步
一 数据库内容 数据库内容自行设计和填充数据
二 后台功能代码
目录结构图
下面正式欣赏代码
1 bean包
bean包里的Department.java代码
package com.hnpi.bean;public class Department {private int id;private String branch;public int getId() {return id;}public void setId(int id) {this.id id;}public String getBranch() {return branch;}public void setBranch(String branch) {this.branch branch;}public Department() {super();// TODO Auto-generated constructor stub}public Department(int id, String branch) {super();this.id id;this.branch branch;}}
bean包里的User.java代码
package com.hnpi.bean;public class User {private int id;private String name;private String pwd;private String rname;private String branch;private String role;public int getId() {return id;}public void setId(int id) {this.id id;}public String getName() {return name;}public void setName(String name) {this.name name;}public String getPwd() {return pwd;}public void setPwd(String pwd) {this.pwd pwd;}public String getRname() {return rname;}public void setRname(String rname) {this.rname rname;}public String getBranch() {return branch;}public void setBranch(String branch) {this.branch branch;}public String getRole() {return role;}public void setRole(String role) {this.role role;}public User() {super();// TODO Auto-generated constructor stub}public User(int id, String name, String pwd, String rname, String branch,String role) {super();this.id id;this.name name;this.pwd pwd;this.rname rname;this.branch branch;this.role role;}}
2 servlet包
servlet 包里的LoginServlet.java代码
package com.hnpi.servlet;import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import com.hnpi.util.DBUtil;public class LoginServlet extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {doPost(request, response);}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {String name request.getParameter(name);String pwd request.getParameter(pwd);request.setCharacterEncoding(utf-8);response.setContentType(text/html);boolean flag false;Connection conn DBUtil.getConn();PreparedStatement ps null;ResultSet rs null;String sql select * from users where name ? and pwd ?;try {ps conn.prepareStatement(sql);ps.setString(1, name);ps.setString(2, pwd);rs ps.executeQuery();if(rs.next()){flag true;}else{flag false;}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{DBUtil.closeConn(conn, ps, rs);}if(flag){response.sendRedirect(list);}else{response.sendRedirect(login.jsp);}}}
servlet 包里的RegisterServlet.java代码
package com.hnpi.servlet;import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import com.hnpi.util.DBUtil;public class RegisterServlet extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {doPost(request, response);}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {request.setCharacterEncoding(utf-8);response.setContentType(text/html);String name request.getParameter(name);String pwd request.getParameter(pwd);String rname request.getParameter(rname);String branch request.getParameter(branch);String role request.getParameter(role);Connection conn DBUtil.getConn();PreparedStatement ps null;String sql insert into users(name,pwd,rname,branch,role) values(?,?,?,?,?);try {ps conn.prepareStatement(sql);ps.setString(1, name);ps.setString(2, pwd);ps.setString(3, rname);ps.setString(4, branch);ps.setString(5, role);ps.executeUpdate();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{DBUtil.closeConn(conn, ps, null);}response.sendRedirect(login.jsp);}}
servlet 包里的ToRegisterServlet.java代码
package com.hnpi.servlet;import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
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 com.hnpi.bean.Department;
import com.hnpi.util.DBUtil;public class ToRegisterServlet extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {doPost(request, response);}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {request.setCharacterEncoding(utf-8);response.setContentType(text/html);Connection conn DBUtil.getConn();PreparedStatement ps null;ResultSet rs null;String sql select * from department;ListDepartment depts new ArrayListDepartment();try {ps conn.prepareStatement(sql);rs ps.executeQuery();while(rs.next()){Department dept new Department();dept.setId(rs.getInt(1));dept.setBranch(rs.getString(2));depts.add(dept);}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{DBUtil.closeConn(conn, ps, rs);}HttpSession session request.getSession();session.setAttribute(deptList, depts);response.sendRedirect(register.jsp);}}
servlet 包里的UserDelServlet.java代码
package com.hnpi.servlet;import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import com.hnpi.util.DBUtil;public class UserDelServlet extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {doPost(request, response);}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {String id request.getParameter(id);request.setCharacterEncoding(utf-8);response.setContentType(text/html);Connection conn DBUtil.getConn();PreparedStatement ps null;String sql delete from users where id ?;try {ps conn.prepareStatement(sql);ps.setString(1, id);ps.executeUpdate();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{DBUtil.closeConn(conn, ps, null);}response.sendRedirect(list);}}
servlet 包里的UserListServlet.java代码
package com.hnpi.servlet;import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
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 com.hnpi.bean.Department;
import com.hnpi.bean.User;
import com.hnpi.util.DBUtil;public class UserListServlet extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {doPost(request, response);}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {request.setCharacterEncoding(utf-8);response.setContentType(text/html);Connection conn DBUtil.getConn();PreparedStatement ps null;ResultSet rs null;String sql select * from users;ListUser users new ArrayListUser();try {ps conn.prepareStatement(sql);rs ps.executeQuery();while(rs.next()){User user new User();user.setId(rs.getInt(1));user.setName(rs.getString(2));user.setPwd(rs.getString(3));user.setRname(rs.getString(4));user.setBranch(rs.getString(5));user.setRole(rs.getString(6));users.add(user);}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{DBUtil.closeConn(conn, ps, rs);}HttpSession session request.getSession();session.setAttribute(userList, users);response.sendRedirect(userList.jsp);}}
servlet 包里的UserUpdateServlet.java代码
package com.hnpi.servlet;import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import com.hnpi.util.DBUtil;public class UserUpdateServlet extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {doPost(request, response);}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {request.setCharacterEncoding(utf-8);response.setContentType(text/html);String id request.getParameter(id);String name request.getParameter(name);String pwd request.getParameter(pwd);String rname request.getParameter(rname);String branch request.getParameter(branch);String role request.getParameter(role);Connection conn DBUtil.getConn();PreparedStatement ps null;String sql update users set name ?, pwd ?, rname ?, branch ?, role ? where id ?;try {ps conn.prepareStatement(sql);ps.setString(1, name);ps.setString(2, pwd);ps.setString(3, rname);ps.setString(4, branch);ps.setString(5, role);ps.setInt(6, Integer.parseInt(id));ps.executeUpdate();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{DBUtil.closeConn(conn, ps, null);}response.sendRedirect(list);}}
3 util包
DBUtil.java
package com.hnpi.util;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;public class DBUtil {public static Connection getConn(){String url jdbc:sqlserver://localhost:1433;databaseNameStaff;String user sa;String pwd 1;Connection conn null;try {Class.forName(com.microsoft.sqlserver.jdbc.SQLServerDriver);conn DriverManager.getConnection(url, user, pwd);} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (ClassNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();}return conn;}public static void closeConn(Connection conn, PreparedStatement ps, ResultSet rs){if(conn!null){try {conn.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}if(ps!null){try {ps.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}if(rs!null){try {rs.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}}
4 JSP页面
login.jsp页面
% page languagejava importjava.util.* pageEncodingutf-8%
%
String path request.getContextPath();
String basePath request.getScheme()://request.getServerName():request.getServerPort()path/;
%!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN
htmlheadbase href%basePath%titleMy JSP index.jsp starting page/titlemeta http-equivpragma contentno-cachemeta http-equivcache-control contentno-cachemeta http-equivexpires content0 meta http-equivkeywords contentkeyword1,keyword2,keyword3meta http-equivdescription contentThis is my page!--link relstylesheet typetext/css hrefstyles.css--/headbodyform actionlogin methodpost账号input typetext namenamebr密码input typepassword namepwdbrinput typesubmit value登陆a hreftoRegister注册/a/form/body
/html
register.jsp页面
%page importcom.hnpi.bean.Department%
% page languagejava importjava.util.* pageEncodingutf-8%
%
String path request.getContextPath();
String basePath request.getScheme()://request.getServerName():request.getServerPort()path/;
%!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN
htmlheadbase href%basePath%titleMy JSP register.jsp starting page/titlemeta http-equivpragma contentno-cachemeta http-equivcache-control contentno-cachemeta http-equivexpires content0 meta http-equivkeywords contentkeyword1,keyword2,keyword3meta http-equivdescription contentThis is my page!--link relstylesheet typetext/css hrefstyles.css--/headbodyform actionregister methodpost账号input typetext namenamebr密码input typepassword namepwdbr真实姓名input typetext namernamebr部门select namebranch%ListDepartment depts (List)session.getAttribute(deptList);for(Department dept : depts){%option id%dept.getId() %%dept.getBranch() %/option%}%/selectbr角色select nameroleoption经理/optionoption员工/option/selectinput typesubmit value注册/form/body
/html
userList.jsp页面
%page importcom.hnpi.bean.User%
% page languagejava importjava.util.* pageEncodingutf-8%
%
String path request.getContextPath();
String basePath request.getScheme()://request.getServerName():request.getServerPort()path/;
%!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN
htmlheadbase href%basePath%titleMy JSP userList.jsp starting page/titlemeta http-equivpragma contentno-cachemeta http-equivcache-control contentno-cachemeta http-equivexpires content0 meta http-equivkeywords contentkeyword1,keyword2,keyword3meta http-equivdescription contentThis is my page!--link relstylesheet typetext/css hrefstyles.css--/headbodytabletheadtrthID/thth账号/thth密码/thth真实姓名/thth部门/thth角色/thth colspan2操作/th/tr/theadtbody%ListUser users (List)session.getAttribute(userList);for(User user : users){%trtd%user.getId() %/tdtd%user.getName() %/tdtd%user.getPwd() %/tdtd%user.getRname() %/tdtd%user.getBranch() %/tdtd%user.getRole() %/tdtda hrefdel?id%user.getId() %删除/a/tdtda hrefuserUpdate.jsp?id%user.getId() %更新/a/td/tr%}%/tbody/table/body
/html
userUpdate.jsp页面
%page importcom.hnpi.bean.Department%
%page importjava.sql.ResultSet%
%page importjava.sql.SQLException%
%page importjava.sql.PreparedStatement%
%page importcom.hnpi.util.DBUtil%
%page importjava.sql.Connection%
% page languagejava importjava.util.* pageEncodingutf-8%
%
String path request.getContextPath();
String basePath request.getScheme()://request.getServerName():request.getServerPort()path/;
%!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN
htmlheadbase href%basePath%titleMy JSP userUpdate.jsp starting page/titlemeta http-equivpragma contentno-cachemeta http-equivcache-control contentno-cachemeta http-equivexpires content0 meta http-equivkeywords contentkeyword1,keyword2,keyword3meta http-equivdescription contentThis is my page!--link relstylesheet typetext/css hrefstyles.css--/headbody%String id request.getParameter(id);Connection conn DBUtil.getConn();PreparedStatement ps null;ResultSet rs null;String sql select * from users where id ?;try {ps conn.prepareStatement(sql);ps.setInt(1, Integer.parseInt(id));rs ps.executeQuery();while(rs.next()){String name rs.getString(name);String pwd rs.getString(pwd);String rname rs.getString(rname);String branch rs.getString(branch);String role rs.getString(role);%form actionupdate methodpostID:input typetext readonlyreadonly nameid value%id %br账号input typetext namename value%name %br密码input typepassword namepwd value%pwd %br真实姓名input typetext namername value%rname %br部门select namebranchoption value生产部%if(branch.equals(生产部)){%selected%}%生产部/optionoption value销售部%if(branch.equals(销售部)){%selected%}%销售部/optionoption value研发部%if(branch.equals(研发部)){%selected%}%研发部/option/selectbr角色select nameroleoption经理/optionoption员工/option/selectbrinput typesubmit value注册/form%}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{DBUtil.closeConn(conn, ps, rs);}%/body
/html
看到这里相信你已经有深刻的了解快去尝试一下吧。
获取更多关注我呦