BAEL-1343 MVC Architecture with Servlets and JSP code (#3624)

* BAEL-1343 MVC Architecture with Servlets and JSP code

* BAEL-1343 code refactoring

* BAEL-1343 code refactoring

* BAEL-1343 updated code formatting

* BAEL-1343 code refactoring
This commit is contained in:
haseebahmad11
2018-02-14 05:49:46 +05:00
committed by Predrag Maric
parent 3d4a179ca3
commit bcc3b6ed95
7 changed files with 176 additions and 1 deletions
@@ -0,0 +1,43 @@
package com.baeldung.controller;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.baeldung.service.StudentService;
/**
*
* @author haseeb
*
*/
@WebServlet(name = "StudentServlet", urlPatterns = "/student-record")
public class StudentServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
StudentService studentService = new StudentService();
String studentID = request.getParameter("id");
if (studentID != null) {
int id = Integer.parseInt(studentID);
request.setAttribute("studentRecord", studentService.getStudent(id));
}
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/jsp/student-record.jsp");
dispatcher.forward(request, response);
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
}
}