jtahstu的博客

root@jtahstu.com   Github   英文博客  

最新碎语:以后没事写写小的知识点吧

您的位置:jtahstu的博客 >笔记> 大三下软件项目开发实训第七天 - 物流管理系统v1.0

大三下软件项目开发实训第七天 - 物流管理系统v1.0

笔记

目标:正是介入物流管理系统------基础信息管理模块。
功能:用户(仓库管理员)登陆,查看本仓库中的商品,货位情况
      先关的合作公司情况。
      用户表,客户档案,商品表,货位表。
========================后台管理系统============================
功能:完成客户档案信息的显示,在框架中。
      1、在mysql中创建客户档案的数据库和插入测试数据。
CREATE TABLE kehudangan(
  kh_bh VARCHAR(30),---客户编号
  kh_bm VARCHAR(30),---客户编码(企业的企业码)
  kh_mc VARCHAR(30),---客户名称(企业名称)
  kh_jc VARCHAR(30),---客户简称
  kh_dh VARCHAR(30),---客户电话
  kh_dz VARCHAR(30),---客户地址
  kh_lxr VARCHAR(30),--客户联系人
  kh_email VARCHAR(30),-客户邮箱
  kh_cz VARCHAR(30)----客户传真
)ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
2、创建表格对应的bean对象和拷贝驱动到lib文件下。
3、创建bean对象对应的子DAO----对客户档案表的所有操作。
   查询方法和遍历方法
4、show.do  ShowServlet.java
        //查询客户档案所有信息
 List<Kehudangan> list=new KehudanganDAO().reqKehudangan();
 //保存数据
 request.setAttribute("khlist", list);
 request.getRequestDispatcher("kehudangan.jsp").forward(request, response);
5、创建kehudangan.jsp
   <%
      List<Kehudangan> list=(List<Kehudangan>)request.getAttribute("kehulist");
   %>
   <%for(int i=0;i<list.size();i++){ %>
6、测试
   在left.jsp中修改href:
       <li><a href="show.do" target="right">客户档案</a></li>
       第一错:驱动没有拷贝
       第二个错:取值名称写错了。
   最终得到了值。
功能2:删除用户信息
     id号的作用:是给程序唯一标识数据用的,对用户而言没有任何的意义。
     第一步:在子dao中写杀出方法
     public void delKehudangan(String kh_bh){
       String  sql="delete from kehudangan where kh_bh='"+kh_bh+"'";
          super.update(sql);
      }
     第二步:创建DelServlet---del.do
               //得到web前端传过来的id号
  String kh_bh=request.getParameter("kh_bh");
  //掉子dao中的方法
  new KehudanganDAO().delKehudangan(kh_bh);
  //重定向----跟之前的请求没有关系
  response.sendRedirect("show.do");
    第三步:kehudangan.jsp中如何传给del.do数据
          <a href="del.do?kh_bh=<%=list.get(i).getKh_bh() %>">删除</a>
          其中kh_bh名称必须和getParameter("kh_bh");名称一样。
    第四步:测试
            在主界面中点击删除按钮。
注意点:
   1、当赋值项目的时候,名称一定要记得变化。

DelServlet.java

package com.it.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.it.dao.KehudanganDAO;
public class DelServlet extends HttpServlet {
 /**
  * Constructor of the object.
  */
 public DelServlet() {
  super();
 }
 /**
  * Destruction of the servlet. <br>
  */
 public void destroy() {
  super.destroy(); // Just puts "destroy" string in log
  // Put your code here
 }
 /**
  * The doGet method of the servlet. <br>
  *
  * This method is called when a form has its tag value method equals to get.
  * 
  * @param request the request send by the client to the server
  * @param response the response send by the server to the client
  * @throws ServletException if an error occurred
  * @throws IOException if an error occurred
  */
 public void doGet(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  //得到web前端传过来的id号
  String kh_bh=request.getParameter("kh_bh");
  //掉子dao中的方法
  new KehudanganDAO().delKehudangan(kh_bh);
  //重定向----跟之前的请求没有关系
  response.sendRedirect("show.do");
 }
 /**
  * The doPost method of the servlet. <br>
  *
  * This method is called when a form has its tag value method equals to post.
  * 
  * @param request the request send by the client to the server
  * @param response the response send by the server to the client
  * @throws ServletException if an error occurred
  * @throws IOException if an error occurred
  */
 public void doPost(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  response.setContentType("text/html");
  PrintWriter out = response.getWriter();
  out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
  out.println("<HTML>");
  out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
  out.println("  <BODY>");
  out.print("    This is ");
  out.print(this.getClass());
  out.println(", using the POST method");
  out.println("  </BODY>");
  out.println("</HTML>");
  out.flush();
  out.close();
 }
 /**
  * Initialization of the servlet. <br>
  *
  * @throws ServletException if an error occurs
  */
 public void init() throws ServletException {
  // Put your code here
 }
}

ShowServlet.java

package com.it.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.it.bean.Kehudangan;
import com.it.dao.KehudanganDAO;
public class ShowServlet extends HttpServlet {
 /**
  * Constructor of the object.
  */
 public ShowServlet() {
  super();
 }
 /**
  * Destruction of the servlet. <br>
  */
 public void destroy() {
  super.destroy(); // Just puts "destroy" string in log
  // Put your code here
 }
 /**
  * The doGet method of the servlet. <br>
  *
  * This method is called when a form has its tag value method equals to get.
  * 
  * @param request the request send by the client to the server
  * @param response the response send by the server to the client
  * @throws ServletException if an error occurred
  * @throws IOException if an error occurred
  */
 public void doGet(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  doPost(request, response);
 }
 /**
  * The doPost method of the servlet. <br>
  *
  * This method is called when a form has its tag value method equals to post.
  * 
  * @param request the request send by the client to the server
  * @param response the response send by the server to the client
  * @throws ServletException if an error occurred
  * @throws IOException if an error occurred
  */
 public void doPost(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  //查询客户档案所有信息
  List<Kehudangan> list=new KehudanganDAO().reqKehudangan();
  //保存数据
  request.setAttribute("khlist", list);
  System.out.println(list.size());
  request.getRequestDispatcher("kehudangan.jsp").forward(request, response);
 }
 /**
  * Initialization of the servlet. <br>
  *
  * @throws ServletException if an error occurs
  */
 public void init() throws ServletException {
  // Put your code here
 }
}

kehudangan.jsp

<%@page import="com.it.bean.Kehudangan"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
 String path = request.getContextPath();
 String basePath = request.getScheme() + "://"
   + request.getServerName() + ":" + request.getServerPort()
   + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'kehudangan.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->
<script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
 //表格隔行变色
      $(function(){
        $("#tb1 tr:odd").css("background-color","#eeeeee");
        $("#tb1 tr:even").css("background-color","white");
        $("#tr1").css("background-color","#6795b4");
      });
      //鼠标移到行上,行变色
     $(function(){
         $("#tb1 tr").bind("mousemove",function(){
         $(this).css("background-color","#6795b4");
         $("#tr1").css("background-color","#6795b4");
       });
         $("#tb1 tr").bind("mouseout",function(){
         $("#tb1 tr:odd").css("background-color","#eeeeee");
         $("#tb1 tr:even").css("background-color","white");
         $("#tr1").css("background-color","#6795b4");
       });
       //鼠标移动到超链接上,超链接变色
       $("a").bind("mousemove",function(){
           $(this).css("color","red");
         }); 
       //鼠标离开超链接上,超链接恢复颜色
       $("a").bind("mouseout",function(){
           $(this).css("color","#1b8ff2");
         }); 
        $("#upd").bind(); 
       });
 </script>
<style type="text/css">
body {
 margin: 0px;
}
#tb1 {
 border: #666666;
 width: 1175px;
 border: 1px solid #464646;
 border-collapse: collapse;
}
#tb2 {
 width: 918px;
 border: 1px;
}
#tb1 tr td {
 border: 1px;
 border-color: #464646;
 border-collapse: collapse;
 border-style: solid;
}
#tr1 {
 background-color: #6795b4;
 height: 30px;
 font-size: 18px;
}
#tr1 td {
 color: #FFFFFF;
}
#tr2 {
 background: #eeeeee;
 text-align: center;
}
a {
 text-decoration: none;
}
</style>
</head>
<body>
<%
   List<Kehudangan> list=(List<Kehudangan>)request.getAttribute("khlist");
 %>
 <img alt="" src="images/righttopbanner1.jpg">
 <table id="tb1">
  <tr id="tr1">
   <td height="25" colspan="10"><div align="center">客户档案</div>
   </td>
  </tr>
  <tr id="tr2">
   <td>客户编号</td>
   <td>客户编码</td>
   <td>客户名称</td>
   <td>客户简称</td>
   <td>客户电话</td>
   <td>操作</td>
  </tr>
  <%for(int i=0;i<list.size();i++){ %>
   <tr>
    <td><%=list.get(i).getKh_bh() %></td>
    <td><%=list.get(i).getKh_bm() %></td>
    <td><%=list.get(i).getKh_mc() %></td>
    <td><%=list.get(i).getKh_jc() %></td>
    <td><%=list.get(i).getKh_dh() %></td>
     <td>
        <a href="del.do?kh_bh=<%=list.get(i).getKh_bh() %>">删除</a>
     </td> 
   </tr>
   <%} %>
 </table>
</body>
</html>

---

本文章采用 知识共享署名2.5中国大陆许可协议 进行许可,欢迎转载,演绎或用于商业目的。

---

二维码加载中...

扫一扫移动端访问O(∩_∩)O

发表评论

93 + 45 =
路人甲 表情
看不清楚?点图切换 Ctrl+Enter快速提交
正在加载中……