cn.edu.henu.rjxy.lms.controller.TeaController.java Source code

Java tutorial

Introduction

Here is the source code for cn.edu.henu.rjxy.lms.controller.TeaController.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.edu.henu.rjxy.lms.controller;

import cn.edu.henu.rjxy.lms.dao.StudentDao;
import static cn.edu.henu.rjxy.lms.dao.StudentDao.getStudentById;
import cn.edu.henu.rjxy.lms.dao.TeacherDao;
//import cn.edu.henu.rjxy.lms.server;
import cn.edu.henu.rjxy.lms.dao.TermCourseDao;
import cn.edu.henu.rjxy.lms.dao.TermCourseInfoDao;
import cn.edu.henu.rjxy.lms.model.AutoCourseNode;
import cn.edu.henu.rjxy.lms.model.Mystudent;
import cn.edu.henu.rjxy.lms.model.NewClass;
import cn.edu.henu.rjxy.lms.model.PageBean;
import cn.edu.henu.rjxy.lms.model.StuSelectResult;
import cn.edu.henu.rjxy.lms.model.Teacher;
import cn.edu.henu.rjxy.lms.model.TeacherCourseResult;
import cn.edu.henu.rjxy.lms.model.TeacherMyclassstudent;
import cn.edu.henu.rjxy.lms.model.Tree3;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import net.sf.json.JSONObject;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.io.FileUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

/**
 *
 * @author Name : liubingxu Email : 2727826327qq.com
 */
@Controller
//@RequestMapping("teacher/teacher")
public class TeaController {

    @RequestMapping("teacher")
    public String tea_index(HttpServletRequest request, HttpServletResponse response) {
        return "teacher/Index";
    }

    @RequestMapping("teacher/student")
    public String student(HttpServletRequest request, HttpServletResponse response) {

        return "teacher/mystudent";
    }

    @RequestMapping("teacher/resetpw_p")
    public @ResponseBody String resetpw_p(HttpServletRequest request, HttpServletResponse response) {
        String sn = getCurrentUsername();
        Teacher teacher = TeacherDao.getTeacherBySn(sn);
        String pw = request.getParameter("pw");
        String repw = request.getParameter("repw");
        if (!pw.equals(teacher.getTeacherPwd().toLowerCase())) {
            return "1";
        }
        if (pw.equals(repw.toLowerCase())) {
            return "2";
        }
        teacher.setTeacherPwd(repw);
        TeacherDao.updateTeacherById(teacher);
        return "3";
    }

    @RequestMapping("teacher/mycourse")
    public String alljsp(HttpServletRequest request, HttpServletResponse response) {
        String term = request.getParameter("term");
        String courseid = request.getParameter("courseid");
        String courseName = request.getParameter("courseName");
        request.setAttribute("term", term);
        request.setAttribute("courseid", courseid);
        request.setAttribute("courseName", courseName);
        return "teacher/mycourse";
    }

    @RequestMapping("teacher/teapnda")
    public String teacher(HttpServletRequest request, HttpServletResponse response) {
        String sn = getCurrentUsername();
        Teacher teacher = TeacherDao.getTeacherBySn(sn);
        String name = teacher.getTeacherName();
        String idCard = teacher.getTeacherIdcard();
        String qq = teacher.getTeacherQq();
        String tel = teacher.getTeacherTel();
        request.setAttribute("sn", sn);
        request.setAttribute("name", name);
        request.setAttribute("idCard", idCard);
        request.setAttribute("qq", qq);
        request.setAttribute("tel", tel);
        request.setAttribute("college", teacher.getTeacherCollege());
        request.setAttribute("zc", teacher.getTeacherPosition());
        return "teacher/teapnda";
    }

    @RequestMapping("teacher/updatetea")
    public @ResponseBody String update(HttpServletRequest request, HttpServletResponse response) {
        String a = "0";
        System.out.println("111111111");
        String tsn = getCurrentUsername();
        Teacher teacher = TeacherDao.getTeacherBySn(tsn);
        System.out.println(tsn);
        String qq = request.getParameter("qq");
        teacher.setTeacherQq(qq);
        String name = request.getParameter("name");
        teacher.setTeacherName(name);
        String tel = request.getParameter("tel");
        teacher.setTeacherTel(tel);
        String idCard = request.getParameter("idCard");
        teacher.setTeacherIdcard(idCard);
        TeacherDao.updateTeacherById(teacher);
        return a;
    }

    //http://localhost:8080/lms/teacher/courselist?xueqi=201602
    @RequestMapping(value = "courselist", method = RequestMethod.GET)
    public @ResponseBody List<TeacherCourseResult> courselist(HttpServletRequest request,
            @RequestParam("xueqi") String xueqi) throws UnsupportedEncodingException {
        request.setCharacterEncoding("utf-8");
        String sn = getCurrentUsername();
        Teacher tec = TeacherDao.getTeacherBySn(sn);
        System.out.println(tec.getTeacherSn());
        return TeacherDao.getTeacherCourseByTermSn(Integer.parseInt(xueqi), tec.getTeacherSn());
    }

    //?
    @RequestMapping("teacher/teaPassward")
    public @ResponseBody String teaPassward(HttpServletRequest request) {
        String sn = getCurrentUsername();
        Teacher tec = TeacherDao.getTeacherBySn(sn);
        String lastPw = request.getParameter("passPassward");
        String newPw1 = request.getParameter("passward");
        String newPw2 = request.getParameter("passward1");
        if (!newPw1.equals(newPw2)) {
            return "0";//??
        }
        if (!tec.getTeacherPwd().equals(lastPw)) {
            return "2";//??
        }
        tec.setTeacherPwd(newPw2);
        TeacherDao.updateTeacherById(tec);
        return "3";
    }

    //??
    @RequestMapping("teacher/mystudent")
    public @ResponseBody JSONObject mystudent(HttpServletRequest request, HttpServletResponse response) {
        int pc = Integer.parseInt(request.getParameter("page"));
        int ps = Integer.parseInt(request.getParameter("rows"));
        int classid = Integer.parseInt(request.getParameter("classid"));
        int course_id = Integer.parseInt(request.getParameter("course_id"));
        int term = Integer.parseInt(request.getParameter("term"));
        String sn = getCurrentUsername();
        Teacher tec = TeacherDao.getTeacherBySn(sn);
        int tec_id = tec.getTeacherId();
        System.out.println("classid=" + classid + "\n" + "course_id=" + course_id + "\n" + "term=" + term + "\n"
                + "tec_id=" + tec_id);
        int trem_courseid = TermCourseDao.getTermCourseId(term, course_id, classid, tec_id);
        System.out.println(trem_courseid + "trem_courseid");

        PageBean<StuSelectResult> mystudent = TeacherDao.getStuSelectByTermCourseId(trem_courseid, pc, ps);
        List<Mystudent> beanList = new LinkedList();
        for (int i = 0; i < mystudent.getBeanList().size(); i++) {
            StuSelectResult a = (StuSelectResult) mystudent.getBeanList().get(i);
            Mystudent student = new Mystudent();
            student.setState(a.getState());
            student.setStudentCollege(getStudentById(a.getStuid()).getStudentCollege());
            student.setStudentGrade(getStudentById(a.getStuid()).getStudentGrade());
            student.setStudentId(a.getStuid());
            student.setStudentName(getStudentById(a.getStuid()).getStudentName());
            student.setStudentIdcard(getStudentById(a.getStuid()).getStudentIdcard());
            student.setStudentQq(getStudentById(a.getStuid()).getStudentQq());
            student.setStudentSex(getStudentById(a.getStuid()).getStudentSex());
            student.setStudentSn(getStudentById(a.getStuid()).getStudentSn());
            student.setStudentTel(getStudentById(a.getStuid()).getStudentTel());
            beanList.add(student);
        }
        //?     
        TeacherMyclassstudent b = new TeacherMyclassstudent();
        b.setPc(pc);
        b.setPs(ps);
        b.setTr(mystudent.getTr());
        b.setBeanList(beanList);
        Map<String, Object> jg = new HashMap<>();
        jg.put("total", b.getTr());
        jg.put("rows", b.getBeanList());
        System.out.println("mystudent");
        return JSONObject.fromObject(jg);
    }

    //?
    @RequestMapping("teacher/scstu")
    public @ResponseBody String[] scstu(HttpServletRequest request, HttpServletResponse response) {
        String[] a = new String[1];
        a[0] = "?";
        int term = Integer.parseInt(request.getParameter("term"));
        int classid = Integer.parseInt(request.getParameter("zjd_id"));
        int course_id = Integer.parseInt(request.getParameter("fjd_id"));
        int Stu_id = Integer.parseInt(request.getParameter("stu_id"));
        System.out.println(
                "term = " + term + " classid=" + classid + " course_id=" + course_id + " stu_id = " + Stu_id);
        String sn = getCurrentUsername();
        Teacher tec = TeacherDao.getTeacherBySn(sn);
        int tec_id = tec.getTeacherId();
        int trem_courseid = TermCourseDao.getTermCourseId(term, course_id, classid, tec_id);
        System.out.println("term_courseid= " + trem_courseid);
        //dtermcourseid
        TeacherDao.updateStudentCourse(Stu_id, trem_courseid, true);
        return a;
    }

    //?
    @RequestMapping("teacher/pzstu")
    public @ResponseBody String[] pzstu(HttpServletRequest request, HttpServletResponse response) {
        String[] a = new String[1];
        a[0] = "??";
        int term = Integer.parseInt(request.getParameter("term"));
        int classid = Integer.parseInt(request.getParameter("zjd_id"));
        int course_id = Integer.parseInt(request.getParameter("fjd_id"));
        int Stu_id = Integer.parseInt(request.getParameter("stu_id"));
        System.out.println(
                "term = " + term + " classid=" + classid + " course_id=" + course_id + " stu_id = " + Stu_id);
        String sn = getCurrentUsername();
        Teacher tec = TeacherDao.getTeacherBySn(sn);
        int tec_id = tec.getTeacherId();
        int trem_courseid = TermCourseDao.getTermCourseId(term, course_id, classid, tec_id);
        System.out.println("term_courseid= " + trem_courseid);
        //dtermcourseid
        TeacherDao.updateStudentCourse(Stu_id, trem_courseid, false);
        return a;
    }

    //?
    @RequestMapping("teacher/pzPLstu")
    public @ResponseBody String[] pzPLstu(HttpServletRequest request, HttpServletResponse response,
            @RequestParam("jssz[]") int[] stuid) {
        String[] a = new String[1];
        a[0] = "??";
        int term = Integer.parseInt(request.getParameter("term"));
        int classid = Integer.parseInt(request.getParameter("zjdid"));
        int course_id = Integer.parseInt(request.getParameter("fjdid"));
        String sn = getCurrentUsername();
        Teacher tec = TeacherDao.getTeacherBySn(sn);
        int tec_id = tec.getTeacherId();
        int trem_courseid = TermCourseDao.getTermCourseId(term, course_id, classid, tec_id);
        System.out.println("term_courseid= " + trem_courseid);
        //dtermcourseid
        for (int i = 0; i < stuid.length; i++) {
            TeacherDao.updateStudentCourse(stuid[i], trem_courseid, false);
        }
        return a;
    }

    //?,getStuSelectByTermCourseId(trem_courseid,1,300);1300
    @RequestMapping("teacher/xz_xs_xx")
    public @ResponseBody String daochuxuesheng(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        int classid = Integer.parseInt(request.getParameter("zjd_id"));
        int course_id = Integer.parseInt(request.getParameter("fjd_id"));
        int term = Integer.parseInt(request.getParameter("term"));
        String sn = getCurrentUsername();
        Teacher tec = TeacherDao.getTeacherBySn(sn);
        int tec_id = tec.getTeacherId();
        int trem_courseid = TermCourseDao.getTermCourseId(term, course_id, classid, tec_id);
        System.out.println(trem_courseid + "trem_courseid");
        PageBean<StuSelectResult> mystudent = TeacherDao.getStuSelectByTermCourseId(trem_courseid, 1, 300);
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        // ????  
        response.setContentType("application/vnd.ms-excel");
        String codedFileName;
        codedFileName = "??";
        OutputStream fOut = null;
        try {
            // ????  
            codedFileName = java.net.URLEncoder.encode("", "UTF-8");
            response.setHeader("content-disposition", "attachment;filename=" + "student_messsage" + ".xls");
            HSSFWorkbook wb = new HSSFWorkbook();
            // webbooksheet,Excelsheet  
            HSSFSheet sheet = wb.createSheet("");
            // sheet0,??poiExcel?short  
            HSSFRow row = sheet.createRow((int) 0);
            // ?   
            HSSFCellStyle style = wb.createCellStyle();
            style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // ? 
            HSSFCell cell = row.createCell((short) 0);
            cell.setCellValue("?");
            cell.setCellStyle(style);
            cell = row.createCell((short) 1);
            cell.setCellValue("??");
            cell.setCellStyle(style);
            cell = row.createCell((short) 2);
            cell.setCellValue("??");
            cell.setCellStyle(style);
            cell = row.createCell((short) 3);
            cell.setCellValue("");
            cell.setCellStyle(style);
            cell = row.createCell((short) 4);
            cell.setCellValue("");
            cell.setCellStyle(style);
            cell = row.createCell((short) 5);
            cell.setCellValue("");
            cell.setCellStyle(style);
            cell = row.createCell((short) 6);
            cell.setCellValue("?");
            cell.setCellStyle(style);
            cell = row.createCell((short) 7);
            cell.setCellValue("qq");
            cell.setCellStyle(style);
            for (int i = 0; i < mystudent.getBeanList().size(); i++) {
                StuSelectResult a = (StuSelectResult) mystudent.getBeanList().get(i);
                System.out.println(getStudentById(a.getStuid()).getStudentSn());
                row = sheet.createRow((int) i + 1);
                row.createCell((short) 0).setCellValue(getStudentById(a.getStuid()).getStudentSn());
                row.createCell((short) 1).setCellValue(getStudentById(a.getStuid()).getStudentName());
                row.createCell((short) 2).setCellValue(getStudentById(a.getStuid()).getStudentIdcard());
                row.createCell((short) 3).setCellValue(getStudentById(a.getStuid()).getStudentGrade());
                row.createCell((short) 4)
                        .setCellValue((getStudentById(a.getStuid()).getStudentSex()) ? ("") : (""));
                row.createCell((short) 5).setCellValue(getStudentById(a.getStuid()).getStudentCollege());
                row.createCell((short) 6).setCellValue(getStudentById(a.getStuid()).getStudentTel());
                row.createCell((short) 7).setCellValue(getStudentById(a.getStuid()).getStudentQq());

            }

            fOut = response.getOutputStream();
            wb.write(fOut);
        } catch (UnsupportedEncodingException e1) {
        } catch (Exception e) {
        } finally {
            fOut.flush();
            fOut.close();
            session.setAttribute("state", "open");
        }
        System.out.println("?...");
        return "1";

    }

    //?
    @RequestMapping("teacher/kcgs")
    public @ResponseBody List<AutoCourseNode> kcgs() {
        List<AutoCourseNode> list = new LinkedList();
        AutoCourseNode node1 = new AutoCourseNode();
        AutoCourseNode node2 = new AutoCourseNode();
        AutoCourseNode node3 = new AutoCourseNode();
        AutoCourseNode node4 = new AutoCourseNode();
        node1.setId(1);
        node1.setState("open");
        node1.setText("");
        node1.setAttributes("1");
        node2.setId(2);
        node2.setState("open");
        node2.setText("");
        node2.setAttributes("1");
        node3.setId(3);
        node3.setState("open");
        node3.setText("");
        node3.setAttributes("1");
        node4.setId(4);
        node4.setState("open");
        node4.setText("");
        node4.setAttributes("1");
        TeacherCourseResult kcsz = new TeacherCourseResult();
        TeacherCourseResult kcsz1 = new TeacherCourseResult();
        TeacherCourseResult kcsz2 = new TeacherCourseResult();
        TeacherCourseResult kcsz3 = new TeacherCourseResult();
        NewClass children1 = new NewClass(1000, "");
        NewClass children2 = new NewClass(2000, "");
        NewClass children3 = new NewClass(3000, "");
        NewClass children4 = new NewClass(4000, "");
        NewClass children5 = new NewClass(5000, "");
        NewClass children6 = new NewClass(6000, "");
        NewClass children7 = new NewClass(7000, "");
        NewClass children8 = new NewClass(8000, "");
        kcsz.setId(1);
        kcsz.setState("open");
        kcsz.setText("");
        kcsz.setAttributes("2");
        kcsz.getChildren().add(children1);
        kcsz.getChildren().add(children2);
        kcsz1.setId(2);
        kcsz1.setState("open");
        kcsz1.setText("");
        kcsz1.setAttributes("2");
        kcsz1.getChildren().add(children3);
        kcsz1.getChildren().add(children4);
        kcsz2.setId(3);
        kcsz2.setState("open");
        kcsz2.setText("");
        kcsz2.setAttributes("2");
        kcsz2.getChildren().add(children5);
        kcsz2.getChildren().add(children6);
        kcsz3.setId(4);
        kcsz3.setState("open");
        kcsz3.setText("");
        kcsz3.setAttributes("2");
        kcsz3.getChildren().add(children7);
        kcsz3.getChildren().add(children8);
        node1.getChildren().add(kcsz);
        node2.getChildren().add(kcsz1);
        node3.getChildren().add(kcsz2);
        node4.getChildren().add(kcsz3);
        list.add(node1);
        list.add(node2);
        list.add(node3);
        list.add(node4);
        return list;
    }

    //?josn?
    @RequestMapping(value = "saveTree", method = RequestMethod.POST)
    public @ResponseBody String saveTree(HttpServletRequest request, @RequestBody Tree3[] users) throws Exception {
        String sn = getCurrentUsername();
        Teacher tec = TeacherDao.getTeacherBySn(sn);
        String tec_sn = tec.getTeacherSn();
        String tec_name = tec.getTeacherName();
        String collage = tec.getTeacherCollege();
        String term = request.getParameter("term");
        String courseName = request.getParameter("courseName");
        // ...//???????? //
        File f = new File(getFileFolder(request) + term + "/" + collage + "/" + tec_sn + "/" + tec_name + "/"
                + courseName + "/" + "" + "/");
        //??
        if (!f.exists() && !f.isDirectory()) {
            System.out.println("?");
            f.mkdirs();
        } else {
            System.out.println("");
        }
        String ff = getFileFolder(request) + term + "/" + collage + "/" + tec_sn + "/" + tec_name + "/" + courseName
                + "/" + "" + "/";
        List list = new LinkedList();
        String ss = "", aa;
        for (int i = 0; i < users.length - 1; i++) {
            list.add(users[i]);
            aa = JSONObject.fromObject(users[i]) + "";
            ss += aa + ',';
        }
        aa = JSONObject.fromObject(users[3]) + "";
        ss = ss + aa;
        ss = '[' + ss + ']';
        System.out.println(ss);
        OutputStreamWriter pw = null;//?
        pw = new OutputStreamWriter(new FileOutputStream(new File(ff + File.separator + "test.json")), "GBK");
        pw.write(ss);
        pw.close();
        return "1";
    }

    //?josn?
    @RequestMapping("teacher/scTree")
    public @ResponseBody String scTree(HttpServletRequest request) throws FileNotFoundException, IOException {
        String sn = getCurrentUsername();
        Teacher tec = TeacherDao.getTeacherBySn(sn);
        String tec_sn = tec.getTeacherSn();
        String tec_name = tec.getTeacherName();
        String collage = tec.getTeacherCollege();
        String term = request.getParameter("term");
        String courseName = request.getParameter("courseName");
        String ff = getFileFolder(request) + term + "/" + collage + "/" + tec_sn + "/" + tec_name + "/" + courseName
                + "/" + "" + "/" + "test.json";
        String fileContent = "";
        try {
            File f = new File(ff);
            if (f.isFile() && f.exists()) {
                InputStreamReader read = new InputStreamReader(new FileInputStream(f), "gbk");
                BufferedReader reader = new BufferedReader(read);
                String line;
                while ((line = reader.readLine()) != null) {
                    fileContent += line;
                }
                read.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(fileContent);
        return fileContent;
    }

    //??
    @RequestMapping("teacher/lookMulu")
    public @ResponseBody String lookMulu(HttpServletRequest request) {
        String sn = getCurrentUsername();
        Teacher tec = TeacherDao.getTeacherBySn(sn);
        String tec_sn = tec.getTeacherSn();
        String tec_name = tec.getTeacherName();
        String collage = tec.getTeacherCollege();
        String term = request.getParameter("term");
        String courseName = request.getParameter("courseName");
        String ff = getFileFolder(request) + term + "/" + collage + "/" + tec_sn + "/" + tec_name + "/" + courseName
                + "/" + "" + "/" + "test.json";
        File f = new File(ff);
        if (!f.exists()) {
            return "0";//?
        }
        return "1";
    }

    //
    @RequestMapping("teacher/kcnr_sc")
    public @ResponseBody String kcnr_sc(HttpServletRequest request) {
        String sn = getCurrentUsername();
        Teacher tec = TeacherDao.getTeacherBySn(sn);
        String tec_sn = tec.getTeacherSn();
        String tec_name = tec.getTeacherName();
        String collage = tec.getTeacherCollege();
        String term = request.getParameter("term");
        String courseName = request.getParameter("courseName");
        String node1 = request.getParameter("node1");
        String node2 = request.getParameter("node2");
        String node3 = request.getParameter("node3");
        String ff = getFileFolder(request) + term + "/" + collage + "/" + tec_sn + "/" + tec_name + "/" + courseName
                + "/" + "" + "/";
        if (node3.endsWith("null")) {//2
            ff = ff + "/" + node1 + "/" + node2 + "/";
            File f = new File(ff);
            if (!f.exists() && !f.isDirectory()) {
                return "1";
            } else {
                if (deleteDir(f)) {
                    return "1";
                } else {
                    return "0";
                }
            }
        } else {//3
            ff = ff + "/" + node1 + "/" + node2 + "/" + node3 + "/";
            File f = new File(ff);
            if (!f.exists() && !f.isDirectory()) {
                return "1";
            } else {
                if (deleteDir(f)) {
                    return "1";
                } else {
                    return "0";
                }
            }
        }
    }

    //
    @RequestMapping("teacher/kcnr_submit")
    public @ResponseBody String[] kcnr_submit(HttpServletRequest request)
            throws IOException, FileUploadException, Exception {
        String[] s = new String[1];
        String sn = getCurrentUsername();
        Teacher tec = TeacherDao.getTeacherBySn(sn);
        String tec_sn = tec.getTeacherSn();
        String tec_name = tec.getTeacherName();
        String collage = tec.getTeacherCollege();
        String term = request.getParameter("term");
        String courseName = request.getParameter("courseName");
        String node1 = request.getParameter("node1");
        String node2 = request.getParameter("node2");
        String node3 = request.getParameter("node3");
        System.out.println(node1 + " " + node2 + "  " + node3 + "  " + term + "  " + courseName);
        String ff = getFileFolder(request) + term + "/" + collage + "/" + tec_sn + "/" + tec_name + "/" + courseName
                + "/" + "" + "/";
        if (node2.equals("undefined") && node3.equals("undefined")) {//1
            ff = ff + node1;
        } else if (node3.equals("undefined") && (!node2.equals("undefined"))) {//2
            ff = ff + "/" + node1 + "/" + node2 + "/";
        } else if ((!node1.equals("undefined")) && (!node2.equals("undefined")) && (!node3.equals("undefined"))) {//3
            ff = ff + "/" + node1 + "/" + node2 + "/" + node3 + "/";
        }
        File f = new File(ff);
        //??
        if (f.exists() && f.isDirectory()) {
            if (f.listFiles().length > 0) {
                System.out.println("??");
                s[0] = "0";
                return s;
            }
        }
        int length = haveFile(ff);
        if (length == 0) {
            s[0] = ""
                    + "<ol class=\"breadcrumb\" id=\"breadcour\"><p>,?</p></ol>";
            return s;
        }
        String a = readname(ff, 1)[0];
        String ff2 = "../file/" + term + "/" + collage + "/" + tec_sn + "/" + tec_name + "/" + courseName + "/"
                + "" + "/" + node1 + "/" + node2 + "/" + node3 + "/" + a;
        s[0] = "<li><a href=\"" + ff2 + "\">" + a + "</a>&nbsp;<a  onclick=\"kcdg_sc()\">" + "" + "</a></li>";
        s[0] = "<ol class=\"breadcrumb\" id=\"breadcour\"><p>?</p>"
                + s[0] + "</ol>";
        //        System.out.println(" "+file.getOriginalFilename());
        //        DocConverter dc=new DocConverter(f+"/"+file.getOriginalFilename());
        //        boolean res=dc.conver();
        //        String swftmp=(f+"/"+file.getOriginalFilename()).replace(getFileFolder(request), "");
        //        swftmp=swftmp.substring(0,swftmp.lastIndexOf("."))+".swf";
        //        if (res){
        //            System.out.println("?flash??:http://localhost:8080/Web/getswf?uri="+swftmp);
        //        }
        return s;
    }

    //?
    @RequestMapping("teacher/addcourseinfo")
    public @ResponseBody String addcourseinfo(HttpServletRequest request, HttpServletResponse response) {
        String term = request.getParameter("term");
        String courseid = request.getParameter("courseid");
        String info = request.getParameter("arrinfor");
        System.out.println("term=" + term + "\n" + "courseid=" + courseid + "\n" + info);
        TermCourseInfoDao.addCourseInfo(Integer.parseInt(term), Integer.parseInt(courseid), info, 1);
        return "1";
    }

    //
    @RequestMapping("teacher/addcourseoutline")
    public @ResponseBody String addcourseoutline(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        String term = request.getParameter("term");
        String courseid = request.getParameter("courseid");
        String info = request.getParameter("arrinfor");
        System.out.println("term=" + term + "\n" + "courseid=" + courseid + "\n" + info);
        TermCourseInfoDao.addCourseInfo(Integer.parseInt(term), Integer.parseInt(courseid), info, 0);
        return "1";
    }

    //
    @RequestMapping("teacher/scDGwork")
    public @ResponseBody String[] scDGwork(HttpServletRequest request) {
        String[] a = new String[1];
        String term = request.getParameter("term");
        String coursename = request.getParameter("coursename");
        String sn = getCurrentUsername();
        Teacher tec = TeacherDao.getTeacherBySn(sn);
        String collage = tec.getTeacherCollege();
        String ff = getFileFolder(request) + term + "/" + collage + "/" + coursename + "/" + "";
        File f = new File(ff);
        if (!f.exists() && !f.isDirectory()) {
            a[0] = "0";
            return a;//
        }
        if (deleteDir(f)) {
            System.out.println("?");
        }
        a[0] = ""
                + "<ol class=\"breadcrumb\" id=\"breadcour\"><p>,?</p></ol>";
        return a;
    }

    //look
    @RequestMapping("teacher/courdir")
    public @ResponseBody String[] courdir(HttpServletRequest request) {
        String[] s = new String[4];
        String sn = getCurrentUsername();
        Teacher tec = TeacherDao.getTeacherBySn(sn);
        String tec_sn = tec.getTeacherSn();
        String tec_name = tec.getTeacherName();
        String collage = tec.getTeacherCollege();
        String term = request.getParameter("term");
        String courseName = request.getParameter("courseName");
        String node1 = request.getParameter("node1");
        String node2 = request.getParameter("node2");
        String node3 = request.getParameter("node3");
        System.out.println(node1 + " " + node2 + "  " + node3 + "  " + term + "  " + courseName);
        String dir = term + "/" + collage + "/" + tec_sn + "/" + tec_name + "/" + courseName + "/" + ""
                + "/" + node1 + "/" + node2 + "/" + node3 + "/";
        String ff = getFileFolder(request) + term + "/" + collage + "/" + tec_sn + "/" + tec_name + "/" + courseName
                + "/" + "" + "/";
        ff = ff + node1 + "/" + node2 + "/" + node3 + "/";
        String ff2 = "../file/" + dir;
        String ff3 = "../" + "getswf?uri=" + dir;
        String ff4 = "../getvideo?uri=" + dir;
        String[] a = new String[1];
        a[0] = "";
        String dlc = "";
        File f = new File(ff);
        if (!f.exists()) {
            a[0] = "<ol class=\"breadcrumb\" id=\"breadcour\"><p>?</p></ol>";
        }
        if (f.exists() && f.isDirectory()) {
            String[] files = f.list();
            System.out.println(ff + "====" + files.length);
            if (files.length <= 0) {
                a[0] = "<ol class=\"breadcrumb\" id=\"breadcour\"><p>?</p></ol>";
            } else {
                boolean swf = false;
                boolean ddoc = false;

                for (String file : files) {
                    System.out.println(file);
                    if (file.lastIndexOf(".") != -1) {
                        if ((file.substring(file.lastIndexOf("."), file.length())).toLowerCase().equals(".swf")) {
                            swf = true;
                            a[0] = a[0] + "<li><a href=\"" + ff3 + file
                                    + "\" target=\"swfplayer\" onclick=\"setheight()\">" + file
                                    + "</a>&nbsp;<a  onclick=\"kcdg_sc('" + file + "')\">" + "" + "</a></li>";
                        } else if ((file.substring(file.lastIndexOf("."), file.length())).toLowerCase()
                                .equals(".mp4")) {
                            swf = true;
                            a[0] = a[0] + "<li><a href=\"" + ff4 + file
                                    + "\" target=\"swfplayer\" onclick=\"setheight()\">" + file
                                    + "</a>&nbsp;<a  onclick=\"kcdg_sc('" + file + "')\">" + "" + "</a></li>";
                        } else {
                            ddoc = true;
                            dlc = dlc + "<li><a href=\"" + ff2 + file + "\">" + file
                                    + "</a>&nbsp;<a  onclick=\"kcdg_sc('" + file + "')\">" + "" + "</a></li>";
                        }
                    }
                }
                if (swf) {
                    a[0] = "<ol class=\"breadcrumb\" id=\"breadcour\"><p>??</p>"
                            + a[0] + "</ol>";
                }
                if (ddoc) {
                    a[0] = a[0] + "<ol class=\"breadcrumb\" id=\"breadcour\"><p>??</p>"
                            + dlc + "</ol>";
                }
                if (a[0].equals("")) {
                    a[0] = "<ol class=\"breadcrumb\" id=\"breadcour\"><p>?</p></ol>";
                }
            }
        }
        return a;
    }

    //??
    @RequestMapping("teacher/lookDGwork")
    public @ResponseBody String[] lookDGwork(HttpServletRequest request) {
        String term = request.getParameter("term");
        String coursename = request.getParameter("coursename");
        String sn = getCurrentUsername();
        Teacher tec = TeacherDao.getTeacherBySn(sn);
        String tec_sn = tec.getTeacherSn();
        String tec_name = tec.getTeacherName();
        String collage = tec.getTeacherCollege();
        String ff = getFileFolder(request) + term + "/" + collage + "/" + coursename + "/" + "";
        String s[] = new String[2];
        int length = haveFile(ff);
        if (length == 0) {
            s[0] = ""
                    + "<ol class=\"breadcrumb\" id=\"breadcour\"><p>,?</p></ol>";
            s[1] = "0";
            return s;
        }
        String a, b;
        if (readname(ff, 2)[0].endsWith(".swf")) {
            a = readname(ff, 2)[1];
            b = readname(ff, 2)[0];
        } else {
            a = readname(ff, 2)[0];
            b = readname(ff, 2)[1];
        }
        b = term + "/" + collage + "/" + coursename + "/" + "" + "/" + b;
        String ff2 = "../file/" + term + "/" + collage + "/" + coursename + "/" + "/" + a;
        s[0] = "<li><a href=\"" + ff2 + "\">" + a + "</a>&nbsp;<a  onclick=\"scfj()\">" + ""
                + "</a>&nbsp;<a  onclick=\"dgyl('" + b + "')\">" + "" + "</a>&nbsp;<a  onclick=\"gbdgyl()\">"
                + "" + "</a>";
        s[0] = "<ol class=\"breadcrumb\" id=\"breadcour\"><p>?,</p>"
                + s[0] + "</ol>";
        s[1] = "1";
        return s;
    }

    //
    @RequestMapping("teacher/lookcourseDG")
    public @ResponseBody String[] lookcourseDG(HttpServletRequest request, HttpServletResponse response) {
        String term = request.getParameter("term");
        String courseid = request.getParameter("courseid");
        System.out.println(term + " " + courseid);
        String[] a = new String[1];
        a[0] = TermCourseInfoDao.getCourseInfo(Integer.parseInt(term), Integer.parseInt(courseid), 0);
        System.out.println(a[0]);
        return a;
    }

    //?
    @RequestMapping("teacher/lookcourseline")
    public @ResponseBody String[] lookcourseline(HttpServletRequest request, HttpServletResponse response) {
        String term = request.getParameter("term");
        String courseid = request.getParameter("courseid");
        System.out.println(term + " " + courseid);
        String[] a = new String[1];
        a[0] = TermCourseInfoDao.getCourseInfo(Integer.parseInt(term), Integer.parseInt(courseid), 1);
        System.out.println(a[0] + " " + "DG");
        return a;
    }

    //?
    @RequestMapping("teacher/lookisCourseMaster")
    public @ResponseBody String lookisCourseMaster(HttpServletRequest request, HttpServletResponse response) {
        String term = request.getParameter("term");
        String courseid = request.getParameter("courseid");
        String sn = getCurrentUsername();
        Teacher tec = TeacherDao.getTeacherBySn(sn);
        if (TeacherDao.isCourseMaster(Integer.parseInt(term), Integer.parseInt(courseid),
                tec.getTeacherId()) == false) {
            return "0";//?
        }
        return "1";//
    }

    //
    @RequestMapping("teacher/kcsc")
    public @ResponseBody String[] kcsc(HttpServletRequest request, HttpServletResponse response) {
        String[] a = new String[1];
        String sn = getCurrentUsername();
        Teacher tec = TeacherDao.getTeacherBySn(sn);
        String tec_sn = tec.getTeacherSn();
        String tec_name = tec.getTeacherName();
        String collage = tec.getTeacherCollege();
        String term = request.getParameter("term");
        String courseName = request.getParameter("courseName");
        String filename = request.getParameter("filename");
        String node1 = request.getParameter("node1");
        String node2 = request.getParameter("node2");
        String node3 = request.getParameter("node3");
        String ff = getFileFolder(request) + term + "/" + collage + "/" + tec_sn + "/" + tec_name + "/" + courseName
                + "/" + "";
        ff = ff + "/" + node1 + "/" + node2 + "/" + node3 + "/";
        String a1 = ff + filename;//? 
        //     String a2 = ff+getFileNameNoEx(filename)+".swf";//?swf
        File f = new File(a1);
        if (f.exists()) {//
            f.delete();
            System.out.println("no");
        } else {
            a[0] = "0";
        }
        return a;
    }

    //?
    @RequestMapping("teacher/work")
    public @ResponseBody String work(HttpServletRequest request) throws IOException {
        int length = 0;
        String textWork = request.getParameter("arred");//?
        String time = request.getParameter("time");//??
        String starttime = request.getParameter("onetime");//??
        String miaoshu = request.getParameter("miaoshu");
        String coursename = request.getParameter("courseName");
        String term = request.getParameter("term");
        String tec_name = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherName();
        String collage = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherCollege();
        String sn = getCurrentUsername();
        //                                      ?   ??          ??
        String ff = getFileFolder(request) + "homework/" + term + "/" + collage + "/" + sn + "/" + tec_name + "/"
                + coursename + "/";
        file(ff);//??
        length = haveFile(ff);
        ff = ff + (length + 1) + "/";
        file(ff);
        //?html
        OutputStreamWriter pw = null;
        pw = new OutputStreamWriter(new FileOutputStream(new File(ff + File.separator + "textWork.html")), "GBK");
        pw.write(textWork);
        pw.close();
        //??
        PrintStream ps = null;
        ps = new PrintStream(new FileOutputStream(new File(ff + File.separator + "Workall.txt")));
        ps.printf(miaoshu);//??:
        ps.println();
        ;
        ps.println(time);//??:
        ps.println(starttime);//??
        ps.close();
        return "1";
    }

    //?
    @RequestMapping("teacher/xgwork")
    public @ResponseBody String xgwork(HttpServletRequest request) throws IOException {
        String textWork = request.getParameter("arred");//?
        String time = request.getParameter("time");//??
        String miaoshu = request.getParameter("miaoshu");
        String starttime = request.getParameter("starttime");
        String coursename = request.getParameter("courseName");
        String term = request.getParameter("term");
        String id = request.getParameter("id");
        String tec_name = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherName();
        String collage = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherCollege();
        String sn = getCurrentUsername();
        //                                      ?   ??          ??
        String ff = getFileFolder(request) + "homework/" + term + "/" + collage + "/" + sn + "/" + tec_name + "/"
                + coursename + "/" + id + "/";

        //?html
        OutputStreamWriter pw = null;
        pw = new OutputStreamWriter(new FileOutputStream(new File(ff + File.separator + "textWork.html")), "GBK");
        pw.write(textWork);
        pw.close();
        //??
        PrintStream ps = null;
        ps = new PrintStream(new FileOutputStream(new File(ff + File.separator + "Workall.txt")));
        ps.printf(miaoshu);//??:
        ps.println();
        ;
        ps.println(time);//??:
        ps.println(starttime);//??:
        ps.close();
        return "1";
    }

    //
    @RequestMapping(value = "scworkfj", method = RequestMethod.POST)
    public @ResponseBody String course_submit(HttpServletRequest request, @RequestParam("file") MultipartFile file)
            throws IOException, Exception {
        String workid = request.getParameter("workid");
        String coursename = request.getParameter("courseName");
        String term = request.getParameter("term");
        String tec_name = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherName();
        String sn = getCurrentUsername();
        String collage = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherCollege();
        //                                      ?   ??          ??
        String ff = getFileFolder(request) + "homework/" + term + "/" + collage + "/" + sn + "/" + tec_name + "/"
                + coursename + "/" + workid + "/" + 1 + "/";
        file(ff);//??
        if (haveFile(ff) != 0) {
            return "0";
        }
        File f = new File(ff);
        //
        if (!file.isEmpty()) {
            try {
                InputStream in;
                try (FileOutputStream os = new FileOutputStream(f + "/" + file.getOriginalFilename())) {
                    in = file.getInputStream();
                    int b = 0;
                    while ((b = in.read()) != -1) {
                        os.write(b);
                    }
                    os.flush();
                }
                in.close();
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block  
                e.printStackTrace();
            }
        }

        return "1";

    }

    @RequestMapping("teacher/homework_submit")
    public @ResponseBody String homework_submit(HttpServletRequest request,
            @RequestParam("file") MultipartFile file) throws FileNotFoundException, IOException {
        int length = 0;
        String textWork = request.getParameter("arr1");//?
        String time = request.getParameter("time");//??
        String miaoshu = request.getParameter("miaoshu");
        String coursename = request.getParameter("courseName");
        String term = request.getParameter("term");
        String tec_name = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherName();
        String sn = getCurrentUsername();
        String collage = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherCollege();
        //                                      ?   ??          ??
        String ff = getFileFolder(request) + "homework/" + term + "/" + collage + "/" + sn + "/" + tec_name + "/"
                + coursename + "/";
        file(ff);//??
        length = haveFile(ff);
        ff = ff + (length + 1) + "/";
        file(ff);
        //?html
        OutputStreamWriter pw = null;//?
        pw = new OutputStreamWriter(new FileOutputStream(new File(ff + File.separator + "textWork.html")), "GBK");
        pw.write(textWork);
        pw.close();
        //??
        PrintStream ps = null;
        ps = new PrintStream(new FileOutputStream(new File(ff + File.separator + "Workall.txt")));
        ps.printf(miaoshu);//??:
        ps.println();
        ;
        ps.println(time);//??:
        ps.close();
        //
        if (!file.isEmpty()) {
            try {
                InputStream in;
                try (FileOutputStream os = new FileOutputStream(ff + "/" + file.getOriginalFilename())) {
                    in = file.getInputStream();
                    int b = 0;
                    while ((b = in.read()) != -1) {
                        os.write(b);
                    }
                    os.flush();
                }
                in.close();
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block  
                e.printStackTrace();
            }
        }
        return "1";
    }

    //
    @RequestMapping("teacher/ckcourselist")
    public @ResponseBody String[] ckcourselist(HttpServletRequest request) throws IOException {
        String[] a = new String[100000];
        int length = 0;
        String coursename = request.getParameter("courseName");
        String term = request.getParameter("term");
        String tec_name = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherName();
        String sn = getCurrentUsername();
        String colage = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherCollege();
        String ff = getFileFolder(request) + "homework/" + term + "/" + colage + "/" + sn + "/" + tec_name + "/"
                + coursename + "/";
        System.out.println(haveFile(ff));
        length = haveFile(ff);
        a[0] = length + "";//
        for (int i = 1; i <= length; i++) {
            System.out.println(read(ff + "/" + i + "/" + "WorkName.txt"));
            a[i] = readline(ff + "/" + i + "/" + "Workall.txt")[0];
            System.out.println(read(ff + "/" + i + "/" + "homeworkTime.html"));
            a[i + length] = readline(ff + "/" + i + "/" + "Workall.txt")[1];
        }
        return a;
    }

    //?
    @RequestMapping("teacher/worknewwindow")
    public @ResponseBody String[] worknewwindow(HttpServletRequest request) throws IOException {
        String coursename = request.getParameter("courseName");
        String term = request.getParameter("term");
        String id = request.getParameter("id");
        String tec_name = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherName();
        String sn = getCurrentUsername();
        String colage = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherCollege();
        String ff = getFileFolder(request) + "homework/" + term + "/" + colage + "/" + sn + "/" + tec_name + "/"
                + coursename + "/" + id + "/";
        String a = read(ff + "/" + "textWork.html");
        String a2 = readline(ff + "/" + "Workall.txt")[1];//endtime
        String a3 = readline(ff + "/" + "Workall.txt")[2];//starttime
        int length = haveFile(ff + "/" + 1 + "/");
        String[] b = new String[4];
        b[0] = a;//?
        b[1] = a2;//
        b[2] = a3;
        if (length == 1) {
            String a1 = readname(ff + "/" + 1 + "/", 1)[0];
            String ff2 = "../file/" + "homework" + "/" + term + "/" + colage + "/" + sn + "/" + tec_name + "/"
                    + coursename + "/" + id + "/" + 1 + "/";
            ff2 = ff2 + a1;
            String c;
            c = "<li style=\"width:300px\"><a href=\"" + ff2 + "\">" + a1 + "</a>&nbsp;<a  onclick=\"sczyfj()\">"
                    + "" + "</a></li>";
            c = "<ol class=\"breadcrumb\" id=\"breadcour\"><p>?,</p>" + c
                    + "</ol>";
            b[3] = c;
        } else {
            b[3] = "2";
        }
        return b;
    }

    // 
    @RequestMapping("teacher/dlworkfj")
    public @ResponseBody String scworkfj(HttpServletRequest request) throws IOException {
        String coursename = request.getParameter("courseName");
        String term = request.getParameter("term");
        String id = request.getParameter("id");
        String tec_name = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherName();
        String sn = getCurrentUsername();
        String colage = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherCollege();
        String ff = getFileFolder(request) + "homework/" + term + "/" + colage + "/" + sn + "/" + tec_name + "/"
                + coursename + "/" + id + "/";
        int length = haveFile(ff + "/" + 1 + "/");
        if (length == 1) {
            File f = new File(ff + "/" + 1 + "/");
            if (deleteDir(f)) {
                return "1";
            } else {
                return "0";
            }
        }
        return "1";
    }

    // ?
    @RequestMapping("teacher/lkworkbj")
    public @ResponseBody String[] lkworkbj(HttpServletRequest request) throws IOException {
        String[] c = new String[1];
        String coursename = request.getParameter("courseName");
        String term = request.getParameter("term");
        String id = request.getParameter("id");
        String tec_name = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherName();
        String sn = getCurrentUsername();
        String colage = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherCollege();
        String ff = getFileFolder(request) + "uploadhomework/" + term + "/" + colage + "/" + sn + "/" + tec_name
                + "/" + coursename + "/" + id + "/";
        File file = new File(ff);
        if (!file.exists() && !file.isDirectory()) {
            c[0] = "0";
            System.out.println("meiyou");
            return c;//?0
        }
        int length = haveFile(ff);//?
        String[] b = new String[length];
        File[] tempList = file.listFiles();//
        String allString = "", temp;
        for (int i = 0; i < tempList.length; i++) {//
            if (tempList[i].isDirectory()) {//???
                String a = tempList[i].toString();
                temp = a.substring(a.lastIndexOf("/") + 1);
                b[i] = " <a onclick=\"czxs('" + temp + "')\" >" + temp + "</a>";
                allString = allString + b[i];
            }
        }
        if (allString != "") {
            b[0] = allString;
        }
        if (tempList.length == 0) {
            b[0] = "0";
        }
        return b;
    }

    ////?
    @RequestMapping("teacher/lkworkxs")
    public @ResponseBody String[] lkworkxs(HttpServletRequest request) throws IOException {
        String[] c = new String[1];
        String clsssname = request.getParameter("a");
        String coursename = request.getParameter("courseName");
        String term = request.getParameter("term");
        String id = request.getParameter("id");
        String tec_name = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherName();
        String sn = getCurrentUsername();
        String colage = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherCollege();
        String ff = getFileFolder(request) + "uploadhomework/" + term + "/" + colage + "/" + sn + "/" + tec_name
                + "/" + coursename + "/" + id + "/" + clsssname + "/";
        String ff2 = "../file/" + "uploadhomework/" + term + "/" + colage + "/" + sn + "/" + tec_name + "/"
                + coursename + "/" + id + "/" + clsssname + "/";
        int length = haveFile(ff);//?
        String[] b = new String[length + 1];
        if (length == 0) {
            c[0] = "0";
            return c;
        }
        File file = new File(ff);
        File[] tempList = file.listFiles();//
        String allString = "", temp;
        for (int i = 0; i < tempList.length; i++) {//
            if (tempList[i].isDirectory()) {//???
                String a = tempList[i].toString();
                temp = a.substring(a.lastIndexOf("/") + 1);//?
                String fileStudentPath = ff + "/" + temp;
                int studentWorkLength = haveFile(fileStudentPath);//
                String stu_name = StudentDao.getStudentBySn(temp).getStudentName();//??  
                String[] ld = new String[studentWorkLength];
                String[] look = new String[studentWorkLength];//??
                for (int m = 0; m < studentWorkLength; m++) {//???
                    look[m] = "null";//???null
                }
                ld = readname(fileStudentPath, studentWorkLength);//??
                String studentWorktime = "0";//????
                int ml = 0;
                for (int j = 0; j < studentWorkLength; j++) {
                    if (ld[j].equals("submitTime.txt")) {
                        studentWorktime = readline(fileStudentPath + "/" + "submitTime.txt")[0];//??studentWorktime
                    } else {
                        look[ml] = ld[j];//???look
                        ml++;//5ml5.... [0 1 2 3 4 5]  .5
                    }
                }

                System.out.println("" + ml + "");
                if (ml == 0) {
                }
                if (ml == 1) {
                    String a1 = "<tr><td>" + temp + "</td><td>" + stu_name + "</td><td>" + clsssname + "</td><td>"
                            + studentWorktime + "</td><td>";
                    String a2 = "<a href=\"" + ff2 + temp + "/" + look[0] + "\" target=\"" + 0 + "\">" + look[0]
                            + "</a>";
                    allString = allString + a1 + a2 + "</td></tr>";
                } else if (ml == 2) {
                    String a1 = "<tr><td>" + temp + "</td><td>" + stu_name + "</td><td>" + clsssname + "</td><td>"
                            + studentWorktime + "</td><td>";
                    String a2 = "<a href=\"" + ff2 + temp + "/" + look[0] + "\" target=\"" + 0 + "\">" + look[0]
                            + "</a>&nbsp";
                    String a3 = "<a href=\"" + ff2 + temp + "/" + look[1] + "\" target=\"" + 0 + "\">" + look[1]
                            + "</a>";
                    allString = allString + a1 + a2 + a3 + "</td></tr>";
                } else if (ml == 3) {
                    String a1 = "<tr><td>" + temp + "</td><td>" + stu_name + "</td><td>" + clsssname + "</td><td>"
                            + studentWorktime + "</td><td>";
                    String a2 = "<a href=\"" + ff2 + temp + "/" + look[0] + "\" target=\"" + 0 + "\">" + look[0]
                            + "</a>&nbsp";
                    String a3 = "<a href=\"" + ff2 + temp + "/" + look[1] + "\" target=\"" + 0 + "\">" + look[1]
                            + "</a>&nbsp";
                    String a4 = "<a href=\"" + ff2 + temp + "/" + look[2] + "\" target=\"" + 0 + "\">" + look[2]
                            + "</a>";
                    allString = allString + a1 + a2 + a3 + a4 + "</td></tr>";
                } else if (ml == 4) {
                    String a1 = "<tr><td>" + temp + "</td><td>" + stu_name + "</td><td>" + clsssname + "</td><td>"
                            + studentWorktime + "</td><td>";
                    String a2 = "<a href=\"" + ff2 + temp + "/" + look[0] + "\" target=\"" + 0 + "\">" + look[0]
                            + "</a>&nbsp";
                    String a3 = "<a href=\"" + ff2 + temp + "/" + look[1] + "\" target=\"" + 0 + "\">" + look[1]
                            + "</a>&nbsp";
                    String a4 = "<a href=\"" + ff2 + temp + "/" + look[2] + "\" target=\"" + 0 + "\">" + look[2]
                            + "</a>&nbsp";
                    String a5 = "<a href=\"" + ff2 + temp + "/" + look[3] + "\" target=\"" + 0 + "\">" + look[3]
                            + "</a>";
                    allString = allString + a1 + a2 + a3 + a4 + a5 + "</td></tr>";
                } else if (ml == 5) {
                    String a1 = "<tr><td>" + temp + "</td><td>" + stu_name + "</td><td>" + clsssname + "</td><td>"
                            + studentWorktime + "</td><td>";
                    String a2 = "<a href=\"" + ff2 + temp + "/" + look[0] + "\" target=\"" + 0 + "\">" + look[0]
                            + "</a>&nbsp";
                    String a3 = "<a href=\"" + ff2 + temp + "/" + look[1] + "\" target=\"" + 0 + "\">" + look[1]
                            + "</a>&nbsp";
                    String a4 = "<a href=\"" + ff2 + temp + "/" + look[2] + "\" target=\"" + 0 + "\">" + look[2]
                            + "</a>&nbsp";
                    String a5 = "<a href=\"" + ff2 + temp + "/" + look[3] + "\" target=\"" + 0 + "\">" + look[3]
                            + "</a>&nbsp";
                    String a6 = "<a href=\"" + ff2 + temp + "/" + look[4] + "\" target=\"" + 0 + "\">" + look[4]
                            + "</a>";
                    allString = allString + a1 + a2 + a3 + a4 + a5 + a6 + "</td></tr>";
                } else if (ml == 6) {
                    String a1 = "<tr><td>" + temp + "</td><td>" + stu_name + "</td><td>" + clsssname + "</td><td>"
                            + studentWorktime + "</td><td>";
                    String a2 = "<a href=\"" + ff2 + temp + "/" + look[0] + "\" target=\"" + 0 + "\">" + look[0]
                            + "</a>&nbsp";
                    String a3 = "<a href=\"" + ff2 + temp + "/" + look[1] + "\" target=\"" + 0 + "\">" + look[1]
                            + "</a>&nbsp";
                    String a4 = "<a href=\"" + ff2 + temp + "/" + look[2] + "\" target=\"" + 0 + "\">" + look[2]
                            + "</a>&nbsp";
                    String a5 = "<a href=\"" + ff2 + temp + "/" + look[3] + "\" target=\"" + 0 + "\">" + look[3]
                            + "</a>&nbsp";
                    String a6 = "<a href=\"" + ff2 + temp + "/" + look[4] + "\" target=\"" + 0 + "\">" + look[4]
                            + "</a>&nbsp";
                    String a7 = "<a href=\"" + ff2 + temp + "/" + look[5] + "\" target=\"" + 0 + "\">" + look[5]
                            + "</a>";
                    allString = allString + a1 + a2 + a3 + a4 + a5 + a6 + a7 + "</td></tr>";
                }
            }
        }
        b[length] = length + "";
        if (!"".equals(allString)) {
            b[0] = allString;
        }
        return b;
    }

    //
    @RequestMapping("teacher/download")
    public ResponseEntity<byte[]> download(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        String term = request.getParameter("term");
        String courseName = request.getParameter("courseName");
        String workid = request.getParameter("workid");
        String sn = getCurrentUsername();
        String collage = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherCollege();
        String teacherName = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherName();
        String path = getFileFolder(request) + "uploadhomework/" + term + "/" + collage + "/" + sn + "/"
                + teacherName + "/" + courseName + "/" + workid + "/"; // 
        String fileNamelast = workid + ".zip";//??
        file(getFileFolder(request) + "uploadhomework/" + term + "/" + collage + "/" + sn + "/" + teacherName + "/"
                + "");
        String compress = getFileFolder(request) + "uploadhomework/" + term + "/" + collage + "/" + sn + "/"
                + teacherName + "/" + "" + "/" + fileNamelast;
        //?
        ZipCompressor zc = new ZipCompressor(compress);//?   
        zc.compress(path, "", ""); //???
        //?

        File file = new File(compress);
        HttpHeaders headers = new HttpHeaders();
        String fileName = new String(fileNamelast.getBytes("UTF-8"), "iso-8859-1");//???  
        headers.setContentDispositionFormData("attachment", fileName);
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), headers, HttpStatus.CREATED);
    }

    //????
    @RequestMapping("teacher/downloadclas")
    public ResponseEntity<byte[]> downloadclass(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        String term = request.getParameter("term");
        String courseName = request.getParameter("courseName");
        String workid = request.getParameter("workid");
        String classname = request.getParameter("classname");
        String sn = getCurrentUsername();
        String collage = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherCollege();
        String teacherName = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherName();
        String path = getFileFolder(request) + "uploadhomework/" + term + "/" + collage + "/" + sn + "/"
                + teacherName + "/" + courseName + "/" + workid + "/" + classname + "/"; // 
        String fileNamelast = classname + ".zip";//??
        file(getFileFolder(request) + "uploadhomework/" + term + "/" + collage + "/" + sn + "/" + teacherName + "/"
                + "");
        String compress = getFileFolder(request) + "uploadhomework/" + term + "/" + collage + "/" + sn + "/"
                + teacherName + "/" + "" + "/" + fileNamelast;
        //?
        ZipCompressor zc = new ZipCompressor(compress);//?   
        zc.compress(path, "", ""); //???
        //?

        File file = new File(compress);
        HttpHeaders headers = new HttpHeaders();
        String fileName = new String(fileNamelast.getBytes("UTF-8"), "iso-8859-1");//???  
        headers.setContentDispositionFormData("attachment", fileName);
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), headers, HttpStatus.CREATED);
    }

    //?
    @RequestMapping("teacher/clear")
    public @ResponseBody String clear(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String term = request.getParameter("term");
        String sn = getCurrentUsername();
        String collage = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherCollege();
        String teacherName = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherName();
        String path = getFileFolder(request) + "uploadhomework/" + term + "/" + collage + "/" + sn + "/"
                + teacherName + "/" + "";
        File f = new File(path);
        if (f.exists() && f.isDirectory()) {
            System.out.println("----------------");
            if (deleteDir(f)) {
                System.out.println("?");
                return "0";
            }
        } else {
            return "0";
        }
        return "0";
    }

    //??
    public boolean file(String path) {
        File f = new File(path);
        if (!f.exists() && !f.isDirectory()) {
            f.mkdirs();
            return true;
        }
        return true;
    }

    //?
    public int haveFile(String path) {
        int length = 0;
        File f = new File(path);
        if (f.exists() && f.isDirectory()) {
            String[] files = f.list();
            if (files.length == 0) {
                System.out.println("");
                return 0;
            } else {
                length = files.length;
            }
        }
        return length;
    }

    //
    public String read(String ff) {
        String fileContent = "";
        try {
            File f = new File(ff);
            if (f.isFile() && f.exists()) {
                InputStreamReader read = new InputStreamReader(new FileInputStream(f), "gbk");
                BufferedReader reader = new BufferedReader(read);
                String line;
                while ((line = reader.readLine()) != null) {
                    fileContent += line;
                }
                read.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return fileContent;
    }

    //java?txt 
    public String[] readline(String path) throws FileNotFoundException, IOException {
        String[] a = new String[3];
        File file = new File(path);//Text
        BufferedReader br = new BufferedReader(new FileReader(file));//BufferedReader??
        String s = null;
        int i = 0;
        while ((s = br.readLine()) != null) {//readLine 
            a[i] = s;
            i++;
        }
        br.close();
        return a;
    }

    public String[] readname(String ff, int j) {
        String[] a = new String[j];
        File file = new File(ff);
        File[] array = file.listFiles();
        for (int i = 0; i < array.length; i++) {
            if (array[i].isFile()) {
                a[i] = array[i].getName();
            }
        }
        return a;
    }

    /**
     * ??
     * @param dir ?
     * @return 
     */
    private static boolean deleteDir(File dir) {
        if (dir.isDirectory()) {
            String[] children = dir.list();
            //?
            for (int i = 0; i < children.length; i++) {
                boolean success = deleteDir(new File(dir, children[i]));
                if (!success) {
                    return false;
                }
            }
        }
        // ?
        return dir.delete();
    }

    /*
    * Java? ??????
    */
    public String getFileNameNoEx(String filename) {
        if ((filename != null) && (filename.length() > 0)) {
            int dot = filename.lastIndexOf('.');
            if ((dot > -1) && (dot < (filename.length()))) {
                return filename.substring(0, dot);
            }
        }
        return filename;
    }

    public String getCurrentUsername() {
        return SecurityContextHolder.getContext().getAuthentication().getName();
    }

    public String getFileFolder(HttpServletRequest request) {
        String path = this.getClass().getClassLoader().getResource("/").getPath();
        System.out.println(path);
        path = path.replace("build/web/WEB-INF/classes/", "build/web/file/");
        System.out.println(path);
        return path;
    }
}