์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
- ํ ์ด๋ธ
- ๋์
- ๋ฐฑํฑ
- Update
- select
- like
- oracle
- MySQL
- JS
- ๋ณ์
- optionํ๊ทธ
- Ajax
- JavaScript
- ๋ฆฌ๋ ์ค
- ์ธ๋ผ์ธ๋ทฐ
- Spring
- order by
- JSP
- ๋ฐฐ์ด
- ๋์ปค
- ์๋ฐ์คํฌ๋ฆฝํธ
- ํ๋ก๊ทธ๋๋จธ์ค
- ์ปจํธ๋กค๋ฌ
- ๋ช ๋ น์ด
- ๋์ ํ ์ด๋ธ
- ํจ์
- SQL
- post๋ฐฉ์
- ์ฝํ
- DATE_FORMAT
- Today
- Total
bom's happy life
[Spring] JSP์์ ๋ณด๋ธ ๋ฐ์ดํฐ Java์์ ๋ฐ๋ ๋ฐฉ๋ฒ ๋ณธ๋ฌธ
[Spring] JSP์์ ๋ณด๋ธ ๋ฐ์ดํฐ Java์์ ๋ฐ๋ ๋ฐฉ๋ฒ
bompeach 2023. 6. 5. 18:01๋ฌธ์ : JSP ์์ ํผ ํ๊ทธ๋ก ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํด์ ์ปจํธ๋กค๋ฌ์ ๋๊ฒจ์ฃผ์๋๋ฐ, `rentTime` ๊ฐ๋ง ๋์ด๊ฐ๊ณ ๋๋จธ์ง ๊ฐ์ด ๋์ด๊ฐ์ง ์๋๋ค.
.
.
๋ฌธ์ ์ ์ฝ๋ :
function placeRentAdd(rentDate,rentTime) {
alert(rentDate);
alert(rentTime);
var rentYN= confirm("์์ฝํ์๊ฒ ์ต๋๊น?");
if(rentYN) {
var form = document.createElement("form");
form.setAttribute("charset", "utf-8");
form.setAttribute("method", "POST");
form.setAttribute("action", "/reservationForm.do");
var rentInfo = document.createElement("input");
rentInfo.setAttribute("name", "placeNm");
rentInfo.setAttribute("value", "${placeNm}");
rentInfo.setAttribute("name", "rentDate");
rentInfo.setAttribute("value", rentDate);
rentInfo.setAttribute("name", "rentTime");
rentInfo.setAttribute("value", rentTime);
form.appendChild(rentInfo);
form.style.display = "none";
document.body.appendChild(form);
form.submit();
} else {
location.reload();
}
}
์ด๋ ๊ฒ ๋ณด๋ด์ฃผ๋๊น `rentTime`๊ฐ๋ง ๋์ด๊ฐ๊ณ `rentDate` ์ `placeNm` ๊ฐ์ด ์ปจํธ๋กค๋ฌ๋ก ๋์ด๊ฐ์ง ์์๋ค.
๊ทธ ์ด์ ๋ฅผ ์ดํด๋ณด๋, `rentInfo` ์์์ `name` ๊ณผ `value` ์์ฑ์ ์ฌ๋ฌ๋ฒ ์ค์ ํ๊ณ ์์ด์ ์ ๋์ด๊ฐ๋ ๊ฒ์ด์๋ค. ๊ฐ ์์ฑ์ ์ค์ ํ ๋๋ง๋ค ์ด์ ์ค์ ์ด ๋ฎ์ด์ฐ์ฌ์ ๋ง์ง๋ง์ผ๋ก ์ค์ ํ ๊ฐ๋ง ์ ์ฉ์ด ๋์๋ ๊ฒ์ด๋ค. ๊ทธ๋์ `rentDate` ์ `placeNm` ์ ๊ฐ์ด ์ ๋๋ก ์ ๋ฌ๋์ง ๋ชปํ๊ฒ!
.
.
์์ ํ ์ฝ๋ :
var form = document.createElement("form");
form.setAttribute("charset", "utf-8");
form.setAttribute("method", "POST");
form.setAttribute("action", "/reservationForm.do");
var rentInfo1 = document.createElement("input");
rentInfo1.setAttribute("type", "hidden");
rentInfo1.setAttribute("name", "placeNm");
rentInfo1.setAttribute("value", "${placeNm}");
form.appendChild(rentInfo1);
var rentInfo2 = document.createElement("input");
rentInfo2.setAttribute("type", "hidden");
rentInfo2.setAttribute("name", "rentDate");
rentInfo2.setAttribute("value", rentDate);
form.appendChild(rentInfo2);
var rentInfo3 = document.createElement("input");
rentInfo3.setAttribute("type", "hidden");
rentInfo3.setAttribute("name", "rentTime");
rentInfo3.setAttribute("value", rentTime);
form.appendChild(rentInfo3);
form.style.display = "none";
document.body.appendChild(form);
form.submit();
์์ ์ฝ๋์์ `rentInfo1`, `rentInfo2`, `rentInfo3` ๋ก ๊ฐ๊ฐ `placeNm`, `rentDate`, `rentTime` ํ๋๋ฅผ ์์ฑํ๊ณ ์๋ค. ๊ฐ ํ๋๋ฅผ ์จ๊ฒจ์ง(hidden) ํ๋๋ก ์์ฑํ๋ ค๋ฉด `type` ์์ฑ์ `hidden` ์ผ๋ก ์ค์ ํ๋ค. ๊ทธ๋ฆฌ๊ณ `setAttribute` ๋ฅผ ์ฌ์ฉํ์ฌ `name` ๊ณผ `value` ์์ฑ์ ๊ฐ๊ฐ ์ค์ ํ๋ค.
์ด๋ ๊ฒ ์์ ํ ํ์๋ `rentDate`์ `placeNm` ๊ฐ์ด ํผ ๋ฐ์ดํฐ๋ก ์ ํํ๊ฒ ์ ์ก๋๊ณ , ์๋ฒ ์ธก์ `reservationForm` ๋ฉ์๋์์ ํด๋น ๊ฐ์ ๊ฐ์ ธ์ฌ ์ ์๊ฒ ๋๋ค!
์ปจํธ๋กค๋ฌ :
@RequestMapping(value="/reservationForm.do", method = RequestMethod.POST)
public String reservationForm(Model model, HttpServletRequest request) throws Exception {
String placeNm = request.getParameter("placeNm");
String rentDate = request.getParameter("rentDate");
String rentTime = request.getParameter("rentTime");
model.addAttribute("placeNm", placeNm);
model.addAttribute("rentDate", rentDate);
model.addAttribute("rentTime", rentTime);
System.out.println("placeNm: " + placeNm);
System.out.println("rentDate: " + rentDate);
System.out.println("rentTime: " + rentTime);
return "reservationForm";
}
์ด๋ ๊ฒ ์ปจํธ๋กค๋ฌ์์ ๋ฐ์์ฃผ๋ ์ด์ ์ผ ๋ฐ์ดํฐ ๊ฐ์ด ์ ๋ค์ด์จ๋ค!
'Deveolpment Study๐๏ธ > Spring Framework' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Spring] JS๋ก <form>ํ๊ทธ ๋์ ์ผ๋ก ์์ฑํด์ ํ์ฉํ๊ธฐ (0) | 2023.06.05 |
---|---|
[Spring] @RequestMapping _ GET๋ฐฉ์, POST ๋ฐฉ์ (0) | 2023.06.05 |
[Spring] MVC - JSP์ ๋ฐ์ดํฐ ์ ๋ฌ (0) | 2023.05.18 |
[Spring] <form:form>ํ๊ทธ (0) | 2023.05.04 |
Session์์ ๋ณ์๋ด์์ ํ์ id๊ฐ ๊ฐ์ ธ์ค๊ธฐ (0) | 2023.04.12 |