基于java+servlet+ssh项目合同管理系统

本文介绍了一个使用SSH框架(Spring、Struts、Hibernate)开发的合同管理系统,系统采用MVC三层架构,实现了包括管理员在内的用户角色管理和登录功能,通过数据库维护公司之间的关联关系。开发环境包括Eclipse、MySQL、JDK1.8和Tomcat 7,技术栈包括SpringMvc、Mybatis、Spring、Bootstrap等。代码已上传至GitHub供学习参考。
摘要由CSDN通过智能技术生成

今天和一个朋友共同完成了一个合同管理系统项目,我们在开发时选用的框架是ssh(MYECLIPSE)框架。我这个朋友知识有限,只会这个框架,哈哈,都是为了方便他。和往常一样选用简单又便捷的MYECLIPSE作为开发工具,这是一个 后台项目。这个系统的介绍是这样的:该文开发的合同管理系统是典型的管理信息系统(MIS),在此系统中,采用了MVC三层结构,因此该系统的实现主要包括后台数据库的建立和维护、前端应用程序以及中间的应用服务器层的开发三个方面.对于数据库要求建立起数据一致性和完整性强.数据安全性好的库;应用程序则要求具有功能完备,易使用等特点;而中间应用服务器层则应具备可随企业逻辑变化能灵活改变的性能.全面提高了软件的质量与生产率.工程化的思想和面向对象的思想的采用,为该软件的成功和快速的开发提供了指导.合同管理系统是一个办公自动...,一个合同管理系统应包含用户角色有管理员。为了能让用户顺利登陆系统完成相关操作,需要为每种登陆角色设置账户和密码字段。系统中公司之间存在关联关系,我们将其关联关系保存在合同表中。他们的关联关系是这样的合同的公司与公司的mingzi字段对应、合同的公司id与公司的id字段对应

基于java+servlet+ssh项目合同管理系统

包含源程序,数据库脚本。代码和数据库脚本都有详细注释。课题设计仅供参考学习使用,可以在此基础上进行扩展完善

 代码已经上传github,下载地址https://github.com/21503882/project
开发环境:
Eclipse ,MYSQL,JDK1.8,Tomcat 7
涉及技术点:
MVC模式、SpringMvc、Mybatis、Spring、bootstrap、HTML、JavaScript、CSS、JQUERY、log4j、Ajax、maven等
系统采用Mybatis框架实现ORM对象关系映射,前台JSP实现,后台springMvc映射,使用Spring框架进行整合。适合学习J2EE的一段时间的熟手,代码思路清晰,注解详细,数据库用的是mysql5.1,服务器用的tomcat7,JDK版本1.8. 编程软件Eclispe J2EE版本。是典型MVC架构,并且前后台分离
主要功能:

package com.serverlet;
 
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
 
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.json.JSONObject;
 
import sun.misc.BASE64Decoder;
import sun.security.action.GetBooleanAction;
 
import com.bean.Good;
import com.bean.Good_User;
import com.bean.News;
import com.bean.User;
import com.dao.GoodDao;
import com.dao.UserDao;
import com.google.gson.Gson;
import com.sun.org.apache.bcel.internal.generic.NEWARRAY;
 
public class goodServlet extends HttpServlet {
 
    /**
     * Constructor of the object.
     */
    public goodServlet() {
        super();
    }
 
    public void destroy() {
        super.destroy(); // Just puts "destroy" string in log
        // Put your code here
    }
 
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html");
        response.setCharacterEncoding("utf-8");
        request.setCharacterEncoding("utf-8");
        this.doPost(request, response);
    }
 
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html");
        response.setCharacterEncoding("utf-8");
        request.setCharacterEncoding("utf-8");
        String param = request.getParameter("param");
        System.out.println(param);
        if (param != null && param.equals("selectsome")) {
            this.selectsome(request, response);
        } else if (param != null && param.equals("gettel")) {
            this.gettel(request, response);
        } else if (param != null && param.equals("goodadd")) {
            this.goodadd(request, response);
        } else if (param != null && param.equals("myselect")) {
            this.myselect(request, response);
        } else if (param != null && param.equals("ugadd")) {
            this.ugadd(request, response);
        } else if (param != null && param.equals("selectun")) {
            this.selectun(request, response);
        } else if (param != null && param.equals("updategood")) {
            this.updategood(request, response);
        }else if (param != null && param.equals("newsadd")) {
            this.newsadd(request, response);
        }else if (param != null && param.equals("newssele")) {
            this.newssele(request, response);
        }
 
    }
    public void newssele(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
 
        response.setContentType("text/html");
        response.setCharacterEncoding("utf-8");
        request.setCharacterEncoding("utf-8");
        PrintWriter out = response.getWriter();
//        String uno = request.getParameter("uno");
        // String type=request.getParameter("type");
//        System.out.println(uno);
        GoodDao dao = new GoodDao();
        List<News> list;
        list = dao.newssele();
        Gson gson = new Gson();
        System.out.println(gson.toJson(list).toString());
        out.print(gson.toJson(list));
        out.flush();
        out.close();
    }
    public void selectsome(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
 
        response.setContentType("text/html");
        response.setCharacterEncoding("utf-8");
        request.setCharacterEncoding("utf-8");
        PrintWriter out = response.getWriter();
        String name = request.getParameter("name");
        if (name != null)
            name = new String(name.getBytes("ISO-8859-1"), "UTF-8");
 
        String type = request.getParameter("type");
        if (type != null)
            type = new String(type.getBytes("ISO-8859-1"), "UTF-8");
        System.out.println(name);
        GoodDao dao = new GoodDao();
        List<Good> list;
        if (type == null)
            list = dao.selectsome(name);
        else {
            if (name != null) {
                list = dao.selectsome1(name, type);
//                System.out.println("111");
            } else {
                list = dao.selectsome2(type);
//                System.out.println("222");
            }
        }
        Gson gson = new Gson();
//        System.out.println(gson.toJson(list).toString());
        out.print(gson.toJson(list));
        out.flush();
        out.close();
    }
 
    public void selectun(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
 
        response.setContentType("text/html");
        response.setCharacterEncoding("utf-8");
        request.setCharacterEncoding("utf-8");
        PrintWriter out = response.getWriter();
 
        GoodDao dao = new GoodDao();
        List<Good_User> list;
        list = dao.selectun();
        Gson gson = new Gson();
//        System.out.println(gson.toJson(list).toString());
        out.print(gson.toJson(list));
        out.flush();
        out.close();
    }
 
    public void myselect(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
 
        response.setContentType("text/html");
        response.setCharacterEncoding("utf-8");
        request.setCharacterEncoding("utf-8");
        PrintWriter out = response.getWriter();
        String uno = request.getParameter("uno");
        // String type=request.getParameter("type");
        System.out.println(uno);
        GoodDao dao = new GoodDao();
        List<Good> list;
        list = dao.myselect(uno);
        Gson gson = new Gson();
        System.out.println(gson.toJson(list).toString());
        out.print(gson.toJson(list));
        out.flush();
        out.close();
    }
 
    public void ugadd(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
 
        response.setContentType("text/html");
        response.setCharacterEncoding("utf-8");
        request.setCharacterEncoding("utf-8");
        PrintWriter out = response.getWriter();
        String uno = request.getParameter("uno");
        String gno = request.getParameter("gno");
        String gname = request.getParameter("gname");
        gname = new String(gname.getBytes("ISO-8859-1"), "UTF-8");
        System.out.println(uno + gno + gname);
        GoodDao dao = new GoodDao();
        dao.ugadd(uno, gno, gname);
        Gson gson = new Gson();
        out.flush();
        out.close();
    }
 
    private void gettel(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // http://localhost:8080/androidServer/servlet/StuServlet?param=add&sno=111&sname=111&dept=111&age=20
        String uno = request.getParameter("uno");
 
        GoodDao dao = new GoodDao();
        JSONObject root = new JSONObject();
        String tel = dao.gettel(uno);
        root.put("tel", tel);
        PrintWriter out = response.getWriter();
        out.print(root);
        out.flush();
        out.close();
    }
 
    private void updategood(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        // http://localhost:8080/androidServer/servlet/StuServlet?param=add&sno=111&sname=111&dept=111&age=20
        String gno = request.getParameter("gno");
 
        GoodDao dao = new GoodDao();
        // JSONObject root = new JSONObject();
        dao.updategood(gno);
        // root.put("tel", tel);
        PrintWriter out = response.getWriter();
        // out.print(root);
        out.flush();
        out.close();
    }
 
    public void newsadd(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
 
            response.setContentType("text/html");
            response.setCharacterEncoding("utf-8");
            request.setCharacterEncoding("utf-8");
            String jsonString = request.getParameter("jsonString");
            JSONObject json = new JSONObject(jsonString);
            String neirong = json.get("neirong").toString();
            String name = json.get("name").toString();
//            String imagename = getnowtime();
//            String time = json.get("time").toString();
//            String other = json.get("other").toString();
//            String adress = json.get("adress").toString();
            String uno = json.get("uno").toString();
//            String type = json.get("type").toString();
//            GenerateImage(image, uno + imagename);
            
            News news = new News();
            news.setUno(uno);// 0是未认领,1是认领
            news.setName(name);
            news.setNeirong(neirong);
            GoodDao dao = new GoodDao();
            if (dao.addnew(news)) {
                PrintWriter out = response.getWriter();
                out.print("true");
            } else {
                PrintWriter out = response.getWriter();
                out.print("false");
            }
        } catch (Exception e) {
            PrintWriter out = response.getWriter();
            out.print("false");
            e.printStackTrace();
        }
 
    }
    public void goodadd(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
 
            response.setContentType("text/html");
            response.setCharacterEncoding("utf-8");
            request.setCharacterEncoding("utf-8");
            String jsonString = request.getParameter("jsonString");
            JSONObject json = new JSONObject(jsonString);
            String name = json.get("name").toString();
            String image = json.get("image").toString();
            String imagename = getnowtime();
            String time = json.get("time").toString();
            String other = json.get("other").toString();
            String adress = json.get("adress").toString();
            String uno = json.get("uno").toString();
            String type = json.get("type").toString();
            GenerateImage(image, uno + imagename);
            
            Good good = new Good();
            good.setClaimstate(false);// 0是未认领,1是认领
            good.setDescribe(other);
            good.setImagname(uno + imagename);
            good.setName(name);
            good.setTime(time);
            good.setType(type);
            good.setAdress(adress);
            good.setUno(Integer.parseInt(uno));
            GoodDao dao = new GoodDao();
            if (dao.add(good)) {
                PrintWriter out = response.getWriter();
                out.print("true");
            } else {
                PrintWriter out = response.getWriter();
                out.print("false");
            }
        } catch (Exception e) {
            PrintWriter out = response.getWriter();
            out.print("false");
            e.printStackTrace();
        }
 
    }
    public void init() throws ServletException {
        // Put your code here
    }
 
    public static boolean GenerateImage(String imgStr, String filename) { // 对字节数组字符串进行Base64解码并生成图片
        if (imgStr == null) // 图像数据为空
            return false;
        BASE64Decoder decoder = new BASE64Decoder();
        try {
            // Base64解码
            byte[] b = decoder.decodeBuffer(imgStr);
            for (int i = 0; i < b.length; ++i) {
                if (b[i] < 0) {// 调整异常数据
                    b[i] += 256;
                }
            }
            // 生成jpeg图片
            String imgFilePath = "D:/图片/" + filename + ".jpg";// 新生成的图片
            OutputStream out = new FileOutputStream(imgFilePath);
            out.write(b);
            out.flush();
            out.close();
            return true;
        } catch (Exception e) {
            return false;
        }
    }
 
    public static String getnowtime() {
 
        // 获取当前时间
        Date date = new Date();
        // SimpleDateFormat sdf = new
        // SimpleDateFormat("",Locale.SIMPLIFIED_CHINESE);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd",
                Locale.SIMPLIFIED_CHINESE);
        // 添加格式化格式
        sdf.applyPattern("yyyyMMddHHmmss");
        String timeStr = sdf.format(new Date());
        System.out.println(timeStr);
        return timeStr;
    }
}
 代码已经上传github,下载地址https://github.com/21503882/project

一个合同管理系统应包含用户角色有管理员。为了能让用户顺利登陆系统完成相关操作,需要为每种登陆角色设置账户和密码字段。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值