-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddProfileServlet.java
More file actions
66 lines (55 loc) · 2.46 KB
/
Copy pathAddProfileServlet.java
File metadata and controls
66 lines (55 loc) · 2.46 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package Servlet;
import model.Photographer;
import model.ServiceProvider;
import model.Videographer;
import model.ProfileManager;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.UUID;
@WebServlet("/event/profiles/add")
public class AddProfileServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.getRequestDispatcher("/event/EProfile/addProfile.jsp").forward(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// ✅ Get real path to the file
String filePath = getServletContext().getRealPath("/WEB-INF/Data/profiles.txt");
// ✅ Pass the file path to ProfileManager
ProfileManager profileManager = new ProfileManager(filePath);
// Collect form data
String type = req.getParameter("type");
String name = req.getParameter("name");
String bio = req.getParameter("bio");
String[] specialties = req.getParameter("specialties").split(",");
String[] availability = req.getParameter("availability").split(",");
String[] sampleMedia = req.getParameter("sampleMedia").split(",");
double rating = Double.parseDouble(req.getParameter("rating"));
// Create appropriate service provider
ServiceProvider provider;
String id = UUID.randomUUID().toString();
if ("photographer".equalsIgnoreCase(type)) {
provider = new Photographer(id, name, bio,
Arrays.asList(specialties),
Arrays.asList(availability),
Arrays.asList(sampleMedia),
rating);
} else {
provider = new Videographer(id, name, bio,
Arrays.asList(specialties),
Arrays.asList(availability),
Arrays.asList(sampleMedia),
rating);
}
// Save to file
profileManager.addProfile(provider);
// Redirect after success
resp.sendRedirect("/event/profiles?action=view&id=" + id);
}
}