<자료실 insert.jsp>
<%@include file="indexTop.jsp" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<meta charset="UTF-8">
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<div class="w3-main" style="margin-left:340px;margin-right:40px; margin-top:80px;">
<form name="f1" onsubmit="return cehckInsertForm();" action="/insertFun.do" method="post" enctype="multipart/form-data">
<table border="1">
<tr>
<td align="center">글쓴이</td>
<td colspan="3" width="50"><input type="hidden" name="writer" value="${sessionNICK}">${sessionNICK}</td>
</tr>
<tr>
<td align="center" width="10%">Email</td>
<td width="25%">
<input type="hidden" name="email" value="${sessionEMAIL}">${sessionEMAIL}
</td>
<td width="10%" align="center">IP</td>
<td width="25%">
<%
String ip = request.getHeader("X-Forwarded-For");
if(ip == null) ip = request.getRemoteAddr();
%>
<input type="hidden" name="ip" value="<%=ip %>"><%=ip %>
</td>
</tr>
<tr>
<td align="center">제목</td>
<td colspan="3"><input type="text" name="subject" style="width: 95%;"></td>
</tr>
<tr>
<td align="center">내용</td>
<td colspan="3"><textarea name="content" style="width: 95%;height: 200px;"></textarea></td>
</tr>
<tr>
<td align="center">비밀번호</td>
<td colspan="3"><input type="password" name="passwd"></td>
</tr>
<tr>
<td align="center">업로드</td>
<td colspan="3">
<input type="file" name="uploadFile1"><br/>
<input type="file" name="uploadFile2"><br/>
<input type="file" name="uploadFile3"><br/>
</td>
</tr>
<tr>
<td colspan="4" align="center">
<input type="submit" value="글쓰기">
<input type="button" value="글목록" onclick="window.location='/getListFun.do'">
</td>
</tr>
</table>
</form>
<%@include file="indexBottom.jsp" %>
<script>
function cehckInsertForm() {
if(f1.subject.value == ''){
alert("제목을 입력해주세요.");
f1.subject.focus();
return false;
} else if(f1.content.value == ''){
alert("내용을 입력해주세요.")
f1.content.focus();
return false;
} else if(f1.passwd.value == ''){
alert("비밀번호를 입력해주세요.");
f1.passwd.focus();
return false;
}
}
</script>
<자료실 controller 부분>
@RequestMapping(value = "/insertFun.do")
public String insertFun(FunVO vo, HttpServletRequest request) throws IOException {
System.out.println("===>Controller로 insertFun() 접속");
System.out.println("writer : "+vo.getWriter());
MultipartFile uploadFile1 = vo.getUploadFile1();
MultipartFile uploadFile2 = vo.getUploadFile2();
MultipartFile uploadFile3 = vo.getUploadFile3();
String genId1 = UUID.randomUUID().toString().substring(5,12);
String genId2 = UUID.randomUUID().toString().substring(5,12);
String genId3 = UUID.randomUUID().toString().substring(5,12);
String RealPath = request.getSession().getServletContext().getRealPath("/fileSave/");
System.out.println("RealPath : "+RealPath);
if(!uploadFile1.isEmpty()){
String originalFileName1 = uploadFile1.getOriginalFilename();
System.out.println("파일명 : "+originalFileName1);
String saveFileName1 = genId1 + "." + FilenameUtils.getExtension(originalFileName1);
uploadFile1.transferTo(new File(RealPath+saveFileName1));
vo.setFileName1(saveFileName1);
}
if(!uploadFile2.isEmpty()){
String originalFileName2 = uploadFile2.getOriginalFilename();
String saveFileName2 = genId2 + "." + FilenameUtils.getExtension(originalFileName2);
uploadFile2.transferTo(new File(RealPath+saveFileName2));
vo.setFileName1(saveFileName2);
}
if(!uploadFile3.isEmpty()){
String originalFileName3 = uploadFile3.getOriginalFilename();
String saveFileName3 = genId3 + "." + FilenameUtils.getExtension(originalFileName3);
uploadFile3.transferTo(new File(RealPath+saveFileName3));
vo.setFileName3(saveFileName3);
}
funService.insertFun(vo);
return "redirect:getListFun.do";
}
'[프로젝트제작&정리] > 나무바다 제작' 카테고리의 다른 글
[나무바다] 모의쇼핑몰 DB 샘플 데이터 (0) | 2020.01.02 |
---|---|
[나무바다] 각 호스팅 폴더에 ROOT.war 파일을 배포해보자. (0) | 2019.12.23 |
[나무바다] DB 샘플 데이터 (0) | 2019.12.22 |
[나무바다] 하나의 호스트에서 두개의 도메인(서브 도메인)을 사용하자 (0) | 2019.12.20 |
[나무바다] cafe24 외부 도메인 dns 설정 변경방법 (0) | 2019.12.19 |