-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab5_2.txt
39 lines (33 loc) · 1.21 KB
/
lab5_2.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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 javax.servlet.http.HttpSession;
import java.io.IOException;
@WebServlet("/generateResult")
public class StudentResultServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Retrieve student marks from the request
int[] marks = new int[6];
for (int i = 0; i < 6; i++) {
marks[i] = Integer.parseInt(request.getParameter("subject" + (i+1)));
}
// Calculate result
boolean pass = true;
for (int mark : marks) {
if (mark < 40) {
pass = false;
break;
}
}
// Store result in session
HttpSession session = request.getSession();
session.setAttribute("marks", marks);
session.setAttribute("pass", pass);
// Redirect to the result page
response.sendRedirect("result.jsp");
}
}