2-3
예제 6-3
<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>Form Processing</title>
</head>
<body>
<h3>회원가입</h3>
<form action="#" name="member" method="post">
<p> 아이디 : <input type="text" name="id"> <input type="button" value="아이디 중복검사">
<p> 비밀번호 : <input type="password" name="passwd">
<p> 이름 : <input type="text" name="name">
<p> 연락처 : <select name="phone1">
<option value="010">010</option>
<option value="011">011</option>
<option value="016">016</option>
<option value="017">017</option>
<option value="019">019</option>
</select> - <input type="text" maxlength="4" size="4" name="phone2"> -
<input type="text" maxlength="4" size="4" name="phone3">
<p> 성별 : <input type="radio" name="sex" value="남성" checked>남성
<input type="radio" name="sex" value="여성" >여성
<p> 취미 : 독서<input type="checkbox" name="hobby1" checked>
운동<input type="checkbox" name="hobby2">
영화<input type="checkbox" name="hobby3">
<p> <textarea name="comment" cols="30" rows="3" placeholder="가입인사를 입력해주세요"></textarea>
<p> <input type="submit" value="가입하기">
<input type="reset" value="다시쓰기">
</form>
</body>
<html>
예제6-4
<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>Form Processing</title>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
String id = request.getParameter("id");
String passwd = request.getParameter("passwd");
String name = request.getParameter("name");
String phone1 = request.getParameter("phone1");
String phone2 = request.getParameter("phone2");
String phone3 = request.getParameter("phone3");
String sex = request.getParameter("sex");
String hobby1 = request.getParameter("hobby1");
String hobby2 = request.getParameter("hobby2");
String hobby3 = request.getParameter("hobby3");
String comment = request.getParameter("comment");
%>
<p> 아이디 : <%=id%>
<p> 비밀번호 : <%=passwd%>
<p> 이름 : <%=name%>
<p> 연락처 : <%=phone1%>-<%=phone2%>-<%=phone3%>
<p> 성별 : <%=sex%>
<p> 취미 : <%=hobby1%> <%=hobby2%> <%=hobby3%>
<p> 가입 인사 : <%=comment%>
</body>
</html>
예제 6-5
<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>Form Processing</title>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
String id = request.getParameter("id");
String passwd = request.getParameter("passwd");
String name = request.getParameter("name");
String phone1 = request.getParameter("phone1");
String phone2 = request.getParameter("phone2");
String phone3 = request.getParameter("phone3");
String sex = request.getParameter("sex");
String[] hobby = request.getParameterValues("hobby"); = 배열
String comment = request.getParameter("comment");
%>
<p> 아이디 : <%=id%>
<p> 비밀번호 : <%=name%>
<p> 이름 : <%=passwd%>
<p> 연락처 : <%=phone1%>-<%=phone2%>-<%=phone3%>
<p> 성별 : <%=sex%>
<p> 취미 :
<%
if (hobby != null) {
for (int i = 0; i < hobby.length; i++) {
out.println(" " + hobby[i]);
}//end for
}//end if
%>
<p> 가입인사 : <%=comment%>
</body>
</html>
3-4
7장 파일업로드
<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>File Upload</title>
</head>
<body>
<form name="fileForm" method="post" enctype="multipart/form-data"
action="fileupload01_process.jsp">
<p> 이 름 : <input type="text" name="name">
<p> 제 목 : <input type="text" name="subject">
<p> 파 일 : <input type="file" name="filename">
<p> <input type="submit" value="파일 올리기">
</p>
</form>
</body>
</html>
4-5
예제7-3
<%@page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>File Upload</title>
</head>
<body>
<form action="fileupload03.jsp" method="post" enctype="multipart/form-data">
<p> 파 일 : <input type="file" name="filename">
<p> <input type="submit" value="파일 올리기">
</form>
</body>
</html>
파일업로드7-3
<%@page contentType="text/html; charset=utf-8"%>
<%@page import="org.apache.commons.fileupload.*"%>
<%@page import="java.util.*"%>
<%@page import="java.io.*"%>
<html>
<head>
<title>File Upload</title>
</head>
<body>
<%
String fileUploadPath = "D:\\upload";
DiskFileUpload upload = new DiskFileUpload();
List items = upload.parseRequest(request);
Iterator params = items.iterator();
while (params.hasNext()) {
FileItem fileItem = (FileItem) params.next();
if (!fileItem.isFormField()) {
String fileName = fileItem.getName();
fileName = fileName.substring(fileName.lastIndexOf("\\") + 1);
File file = new File(fileUploadPath + "/" + fileName);
fileItem.write(file);
}//end if
}//end while
out.print("업로드완료");
%>
</body>
</html>
'인공지능 > JSP' 카테고리의 다른 글
5.24 JSP (0) | 2021.06.17 |
---|---|
5.17 인공지능 JSP ( 1 ) (0) | 2021.06.05 |
5.18 JSP (2) (0) | 2021.06.05 |
5.20 인공지능 jsp ( 4 ) (0) | 2021.06.05 |