Java tutorial
/* * 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 WebApp.Controller; import WebApp.Model.Incourse; import WebApp.Service.IncourseService; import WebApp.Service.IncourseServiceImp; import WebApp.Util.Constants; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; /** * * @author shamim */ public class IncourseController implements Controller { private static final String COURSE_CODE = "course_code"; private static final String SESSION = "session"; private static final String DEPT_ROLL = "dept_roll"; private static final String INCOURSE_FINAL = "mark_final"; @Override public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView modelAndView = null; String requestedUri = request.getRequestURI(); if (requestedUri.contains(Constants.INCOURSE_FINAL_MARKS_FORM)) { modelAndView = new ModelAndView("insertEachIncourseMarks"); } else if (requestedUri.contains(Constants.INSERT_INCOURSE_FINAL)) { String courseCode = request.getParameter(COURSE_CODE); String session = request.getParameter(SESSION); String deptRoll = request.getParameter(DEPT_ROLL); String incourseFinal = request.getParameter(INCOURSE_FINAL); IncourseService incourseService = new IncourseServiceImp(); incourseService.saveFinal(createIncourse(courseCode, session, deptRoll, incourseFinal)); modelAndView = new ModelAndView("insertEachIncourseMarks"); modelAndView.addObject("message", "successfully inserted incourse marks information"); } return modelAndView; } private Incourse createIncourse(String courseCode, String session, String deptRoll, String incourseFinal) { Incourse incourse = new Incourse(); incourse.setCourseCode(courseCode); incourse.setSession(session); incourse.setDeptRoll(deptRoll); incourse.setTotalObtainMarks(Double.parseDouble(incourseFinal)); return incourse; } }