zoukankan      html  css  js  c++  java
  • 我的第一个项目(人力资源管理之报表管理)

           2014年暑期实习老师要求的是人力资源管理系统,组队后组长分配给的任务是报表管理。

           我做的报表管理,主要的功能是用户输入查询的时间区间和查询部门,然后将数据据库返回的数据显示在浏览器上。用户可以选择是否生成excel表格(表格是保存在固定的电脑地址下《D:》)

          首先列一下系统要求:截图如下(为什么不能插入图片,第一次写不知道怎么插入)。需求要求显示当前月的月首和月末。

          我首先要做的就是处理这些默认值(时间默认值和部门默认值(全部)):

          1、首先从系统获取当前年份与月份:

          

    <%@ page language="java"%>
          <%@ page contentType="text/html; charset=utf-8"%>
          <%@ page import="java.util.*"%>
          <%@ page import="java.text.*"%>
          <%
          String day = "";
          String year1 = new SimpleDateFormat("yyyy").format(Calendar.getInstance().getTime());
          String month1 = new SimpleDateFormat("MM").format(Calendar.getInstance().getTime());
          %>

        2、从数据库获取部门信息(jsp里的代码,在servlet中一样)

           

          部门:&nbsp;&nbsp;&nbsp;&nbsp;
          

    <%
             Form2 db=new Form2(); //连接数据库的类(在下面列出来)
             ArrayList list3=db.getConnection();类中连接数据库和查询的函数
          %>
          <select name="department" >
            <option>全部</option>
            <%
            for(int i=0;i<list3.size();i++){
            javaBean.departmentBean bean=(javaBean.departmentBean)list3.get(i);
            %>
          <option value="<%=bean.getDep_name() %>"><%=bean.getDep_name()%></option>
          <%} %>
          </select>

              Form2类:

          

    public class Form2
    
          {
    
            public ArrayList getConnection()
            {
    
              String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
              String dbURL = "jdbc:sqlserver://172.20.61.19:1433;DatabaseName=Admininstration";
              String user = "sa";
              String password = "1962603840";
              java.sql.Connection connection=null;
    
              ArrayList list1 = new ArrayList();
    
              try
              {
                Class.forName(driverName);
                connection=DriverManager.getConnection(dbURL, user, password);
    
                java.sql.Statement statement = connection.createStatement();
                ResultSet resultSet = statement.executeQuery("select dep_name from department");
    
                while(resultSet.next())
                {
                String dep_name = resultSet.getString("dep_name");
                departmentBean bean1 = new departmentBean();
    
                bean1.setDep_name(dep_name);
    
                list1.add(bean1);
                }
                return list1;
                }
                catch (Exception e)
                {
                e.printStackTrace();
                // TODO: handle exception
                }
                finally{
                  try {
                    connection.close();
                    } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    }
                  }
                return list1;
    
                }
    
           }

         3、从数据库中获取数据并保存在excel表格中,(只能保存在主机上,找时间要探索一下如何在用户电脑上显示)(连接数据库的类中写的)

        

    if (excel.equals("是")) {//excel是从jsp页面选择的是否要生成excel的选择,通过session传递
          try {
            // open file.
            WritableWorkbook book = Workbook.createWorkbook(new File("d:/新聘职工信息.xls"));
            WritableSheet sheet = book.createSheet("Sheet_1", 0);
    
            jxl.write.Label label1 = new jxl.write.Label(0, 0, "序号");
            sheet.addCell(label1);
            jxl.write.Label label2 = new jxl.write.Label(1, 0, "部门名称");
            sheet.addCell(label2);
            jxl.write.Label label3 = new jxl.write.Label(2, 0, "岗位名称");
            sheet.addCell(label3);
            jxl.write.Label label4 = new jxl.write.Label(3, 0, "入职日期");
            sheet.addCell(label4);
    
            for (int i = 0;i < list.size();i ++){
              staff_infBean bean1 = (staff_infBean)list.get(i);
              jxl.write.Label label01 = new jxl.write.Label(0, i+1, bean1.getStaff_id());
              sheet.addCell(label01);
              jxl.write.Label label02 = new jxl.write.Label(1, i+1, bean1.getDepartment());
              sheet.addCell(label02);
              jxl.write.Label label03 = new jxl.write.Label(2, i+1, bean1.getPost());
              sheet.addCell(label03);
              jxl.write.Label label04 = new jxl.write.Label(3, i+1, bean1.getDate_entry());
              sheet.addCell(label04);
            }
           book.write();
           book.close();
           } catch (Exception e) {
            e.printStackTrace();
            }

    4、处理乱码问题

         tomcat下的conf下的server.xml中找到第二个8080处,在8080后面加上  URIEncoding="utf-8"  保存,然后在Servlet文件中加转码语句

    response.setContentType("text/html");
    response.setCharacterEncoding("utf-8");//转码

    PrintWriter out = response.getWriter();//不知道有没有顺序问题,有一次顺序错了,也导致了乱码。

  • 相关阅读:
    无法直接启动带有类库输出类型的项目
    2个页面传值方法
    vs2005 无法附加 绑定句柄无效 解决办法
    认识serializable,序列化
    jsp 连接sql 2008
    有进步,嘎嘎....
    找不到存储过程'dbo.aspnet_CheckSchemaVersion'
    BackOffice Common中实现的相关功能
    MVC中Action相关方法的建议
    mysql的数据库相关维护操作:重启、修改连接数、删除连接
  • 原文地址:https://www.cnblogs.com/ling123/p/3868726.html
Copyright © 2011-2022 走看看