-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsaveProfile.jsp
More file actions
61 lines (47 loc) · 2.05 KB
/
saveProfile.jsp
File metadata and controls
61 lines (47 loc) · 2.05 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
<%@ page import="java.sql.*" %>
<%@ page import="jakarta.servlet.http.Part" %>
<%@ page import="jakarta.servlet.annotation.MultipartConfig" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="db.jsp" %>
<%
request.setCharacterEncoding("UTF-8");
// 입력값 받기
String id = request.getParameter("id");
String nickname = request.getParameter("nickname");
String password = request.getParameter("password");
String message = request.getParameter("message");
//String Lv = request.getParameter("Lv"); //레벨
//String exp = request.getParameter("exp"); //경험치
// 세션에 저장
session.setAttribute("id", id);
session.setAttribute("nickname", nickname);
session.setAttribute("password", password);
session.setAttribute("message", message);
//session.setAttribute("Lv", Lv); //레벨
//session.setAttribute("exp", exp); //경험치
try {
String sql = "INSERT INTO signup (id, nickname, password, message, photo) VALUES (?, ?, ?, ?, ?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, id);
pstmt.setString(2, nickname);
pstmt.setString(3, password);
pstmt.setString(4, message);
// 프로필 사진 처리 (세션에서 가져옴)
String photo = (String) session.getAttribute("photo");
pstmt.setString(5, photo != null ? photo : "");
int result = pstmt.executeUpdate();
if (result > 0) { // 저장 성공
response.sendRedirect("info.jsp");
return;
}
else { // 저장 실패
out.println("<script>alert('프로필 저장 실패'); history.back();</script>");
}
} catch (Exception e) {
e.printStackTrace();
out.println("<script>alert('에러 발생: " + e.getMessage() + "'); history.back();</script>");
} finally {
try { if (pstmt != null) pstmt.close(); } catch (Exception e) {}
try { if (conn != null) conn.close(); } catch (Exception e) {}
}
%>