Search in sources :

Example 6 with Courses

use of Model.Courses in project Happourse_online_study_web by infiq2000.

the class CourseByCategory method doGet.

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    int cid = Integer.parseInt(request.getParameter("cid"));
    try {
        List<Courses> courses = couUtil.getCourseByCategory(cid);
        request.setAttribute("listCourses", courses);
        RequestDispatcher dispatcher = request.getRequestDispatcher("/UserPage.jsp");
        dispatcher.forward(request, response);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : SQLException(java.sql.SQLException) Courses(Model.Courses) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 7 with Courses

use of Model.Courses in project Happourse_online_study_web by infiq2000.

the class Login method doPost.

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String userName = request.getParameter("username");
    String passWord = request.getParameter("password");
    try {
        User user = null;
        Account tmp = accUtil.validation(userName, passWord);
        if (tmp != null) {
            if (!tmp.isType()) {
                user = userUtil.getUser(tmp.getAid());
                List<Courses> courses = userUtil.getAll_Courses();
                request.setAttribute("listCourses", courses);
                request.setAttribute("user_info", user);
                String[] a = user.getFull_name().split(" ");
                String b = a[a.length - 1];
                HttpSession session = request.getSession(true);
                session.setAttribute("name", b);
                session.setAttribute("uid", user.getUid());
                session.setAttribute("aid", user.getAid());
                RequestDispatcher dispatcher = request.getRequestDispatcher("/UserPage.jsp");
                dispatcher.forward(request, response);
            }
        } else {
            request.setAttribute("errorString", "Username or password is incorrect");
            RequestDispatcher dispatcher = request.getRequestDispatcher("/invalidLogin.jsp");
            dispatcher.forward(request, response);
        }
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : Account(Model.Account) User(Model.User) SQLException(java.sql.SQLException) HttpSession(javax.servlet.http.HttpSession) Courses(Model.Courses) RequestDispatcher(javax.servlet.RequestDispatcher) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) SQLException(java.sql.SQLException)

Example 8 with Courses

use of Model.Courses in project Happourse_online_study_web by infiq2000.

the class CourseDetail method doGet.

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    int course_id = Integer.parseInt(request.getParameter("course_id"));
    int uid = (int) request.getSession(false).getAttribute("uid");
    int aid = (int) request.getSession(false).getAttribute("aid");
    try {
        /* Account ac = accUtil.getAccount(aid); */
        Account acc = accUtil.getAccount(aid);
        request.setAttribute("account", acc);
        request.setAttribute("course_id", course_id);
    } catch (SQLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    try {
        Courses detailC = courseUtil.getCourseDetail(course_id);
        request.setAttribute("course_detail", detailC);
        String cate = insUtil.getCate(detailC.getCid());
        request.setAttribute("cate", cate);
        Instructor ins_info = insUtil.getIns_Info(detailC.getIns_id());
        request.setAttribute("ins_info", ins_info);
        List<Chapter> list_chapter = lecUtil.getChapterOfCourse(detailC.getCourses_id());
        request.setAttribute("chapter", list_chapter);
        RequestDispatcher dispatcher;
        if (courseUtil.checkSignedCourse(course_id, uid) == null) {
            dispatcher = request.getRequestDispatcher("/Course_detail.jsp");
        } else {
            dispatcher = request.getRequestDispatcher("/CourseSigned.jsp");
        }
        dispatcher.forward(request, response);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : Account(Model.Account) SQLException(java.sql.SQLException) Instructor(Model.Instructor) Chapter(Model.Chapter) Courses(Model.Courses) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 9 with Courses

use of Model.Courses in project Happourse_online_study_web by infiq2000.

the class RemoveCourse method doGet.

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    int course_id = Integer.parseInt(request.getParameter("course_id"));
    int uid = (int) request.getSession(false).getAttribute("uid");
    request.setAttribute("course_id", course_id);
    try {
        Courses detailC = courseUtil.getCourseDetail(course_id);
        request.setAttribute("course_detail", detailC);
        String cate = insUtil.getCate(detailC.getCid());
        request.setAttribute("cate", cate);
        Instructor ins_info = insUtil.getIns_Info(detailC.getIns_id());
        request.setAttribute("ins_info", ins_info);
        List<Chapter> list_chapter = lecUtil.getChapterOfCourse(detailC.getCourses_id());
        request.setAttribute("chapter", list_chapter);
        courseUtil.removeCourse(uid, course_id);
        RequestDispatcher dispatcher = request.getRequestDispatcher("/Course_detail.jsp");
        dispatcher.forward(request, response);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : SQLException(java.sql.SQLException) Instructor(Model.Instructor) Chapter(Model.Chapter) Courses(Model.Courses) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 10 with Courses

use of Model.Courses in project Happourse_online_study_web by infiq2000.

the class SearchCoursesByName method doGet.

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String txtSearch = request.getParameter("search");
    // txtSearch = txtS.toLowerCase();
    List<Courses> courses = null;
    try {
        courses = couUtil.searchCourseByName(txtSearch);
    } catch (Exception e) {
        System.out.println(e);
    }
    request.setAttribute("listCourses", courses);
    RequestDispatcher dispatcher = request.getRequestDispatcher("/UserPage.jsp");
    dispatcher.forward(request, response);
}
Also used : Courses(Model.Courses) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) RequestDispatcher(javax.servlet.RequestDispatcher)

Aggregations

Courses (Model.Courses)14 RequestDispatcher (javax.servlet.RequestDispatcher)8 SQLException (java.sql.SQLException)7 Connection (java.sql.Connection)6 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 ArrayList (java.util.ArrayList)4 Instructor (Model.Instructor)3 Account (Model.Account)2 Chapter (Model.Chapter)2 User (Model.User)2 IOException (java.io.IOException)2 ServletException (javax.servlet.ServletException)2 HttpSession (javax.servlet.http.HttpSession)1