博主简介:目前专注于大学生项目实战开发,Java定制、代码讲解、毕业答疑辅导以及调试部署、文档报告。全网粉丝8w+,CSDN特邀作者,上市公司架构师,Java新星计划应届导师,多平台领域优质原创作者!
文末获取源码联系
精彩专栏推荐订阅,不然下次找不到哦
Java项目精品实战案例《100套》
小程序项目精品实战案例《100套》
Python项目精品实战案例《100套》
开发技术:
语言【Java 】
框架【后端:javaweb、servlet+jsp,前端:html+css+js、jsp】
数据库【MySQL】
开发环境:jdk1.8、Tomcat8.5(如是SpringBoot框架,则无须配置Tomcat)、Mysql5.7,IDEA(Eclipse、MyEclipse )选其一
2个角色:员工/管理员
1.员工:个人资料管理、销售管理、入库管理等。
2.管理员:员工管理、商品类别管理、商品管理、商品销售管理、采购入库管理以及系统管理等。
1.登录代码【代码如下(示例):】
if(ac.equals("login"))
{
String username = request.getParameter("username");
String password = request.getParameter("pwd1");
String utype = request.getParameter("cx");
String pagerandom = request.getParameter("pagerandom")==null?"":request.getParameter("pagerandom");
String random = (String)request.getSession().getAttribute("random");
if(!pagerandom.equals(random)&&request.getParameter("a")!=null)
{
request.setAttribute("random", "");
go("/index.jsp", request, response);
}
else{
String sql1="";
if (utype.equals("管理员")){sql1 = "select * from allusers where username='"+username+"' and pwd='"+password+"'"; }
if(utype.equals("员工")){sql1 = "select * from yuangong where gonghao='"+username+"' and mima='"+password+"' ";}
List<HashMap> userlist1 = dao.select(sql1);
if(userlist1.size()==1)
{
request.getSession(). setAttribute("username", username);
if (utype.equals("管理员")){
request.getSession(). setAttribute("cx", userlist1.get(0).get("cx"));
}
else
{
request.getSession(). setAttribute("cx", utype);
}
gor("index.jsp", request, response);
}else{
request.setAttribute("error", "");
go("/index.jsp", request, response);
}
}
}
if(ac.equals("adminlogin"))
{
String username = request.getParameter("username");
String password = request.getParameter("pwd");
String utype = request.getParameter("cx");
String pagerandom = request.getParameter("pagerandom")==null?"":request.getParameter("pagerandom");
String random = (String)request.getSession().getAttribute("random");
if(!pagerandom.equals(random)&&request.getParameter("a")!=null)
{
request.setAttribute("random", "");
go("/login.jsp", request, response);
}
else{
String sql1 = "";
if (utype.equals("管理员")){sql1 = "select * from allusers where username='"+username+"' and pwd='"+password+"'"; }
if(utype.equals("员工")){sql1 = "select * from yuangong where gonghao='"+username+"' and mima='"+password+"' ";}
List<HashMap> userlist1 = dao.select(sql1);
if(userlist1.size()==1)
{
request.getSession(). setAttribute("username", username);
if (utype.equals("管理员")){
request.getSession(). setAttribute("cx", userlist1.get(0).get("cx"));
}
else
{
request.getSession(). setAttribute("cx", utype);
}
gor("main.jsp", request, response);
}else{
request.setAttribute("error", "");
go("/login.jsp", request, response);
}
}
}
2.数据库连接【代码如下(示例):】
public Connection getConn()
{
try
{
if(conn==null||conn.isClosed()){
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jspmxxcsglxthsg3286CBmysql?useUnicode=true&characterEncoding=utf8","root","root");
// Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
// conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=jspmxxcsglxthsg3286CB","sa","sa123456");
// Class.forName("net.sourceforge.jtds.jdbc.Driver");
// conn = DriverManager.getConnection("jdbc:jtds:sqlserver://127.0.0.1:1433;databaseName=jspmxxcsglxthsg3286CB","sa","sa123456");
}}
catch(Exception e)
{
e.printStackTrace();
}
return conn;
}
3.验证码实现【代码如下(示例):】
public class QRCode extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String website = request.getParameter("website");
try {
QRCodeUtil.genGR(website, response.getOutputStream());
} catch (WriterException e) {
e.printStackTrace();
}
//String website = request.getAttribute("website").toString();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
Java项目精品实战案例《100套》
小程序项目精品实战案例《100套》
Python项目精品实战案例《100套》
如果大家有任何疑虑,欢迎在下方位置详细交流。