복잡한 양식 데이터를 서브렛으로 읽기

1단계, 등록 페이지 작성
<body>
	<center>
	<h1>  </h1>
		<form method="post" action="Servlet/RegsiterServlet" name="Regsiter">
			<table border="1" width="30%" height="20%">
				<tr>
					<td>  :</td>
					<td><input type="text" name="User_Name"></td>
				</tr>
				<tr>
					<td>  :</td>
					<td><input type="text" name="User_Pass"></td>
				</tr>
				<tr>
					<td>  :</td>
					<td><input type="radio" name="User_Sex" value=" ">  
						<input type="radio" name="User_Sex" value=" "> 
					</td>
				</tr>
				<tr>
					<td>  :</td>
					<td><input type="checkbox" name="User_Favor" value="  ">  
						<input type="checkbox" name="User_Favor" value="  ">   
						<input type="checkbox" name="User_Favor" value="  ">  
						<input type="checkbox" name="User_Favor" value="  ">  
					</td>
				</tr>
				<tr>
					<td>    :</td>
					<td><textarea name="User_Present" cols="30" rows="5"></textarea>
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<center>
							<input type="submit" value="  ">
							<input type="reset" value="  ">
						</center>
					</td>
				</tr>
			</table>
		</form>
	</center>
</body>

2단계, RegisterServlet 작성

		String UserName = req.getParameter("User_Name");
		String UserPass = req.getParameter("User_Pass");
		String UserSex  = req.getParameter("User_Sex");
		String UserPresent = req.getParameter("User_Present");
		String Userfavor[] = req.getParameterValues("User_Favor");

		for (int i=0;i<Userfavor.length;i++){
			Userfavor[i] = changChar(Userfavor[i]);
		}
		UserName = changChar(UserName);
		UserPass = changChar(UserPass);
		UserSex  = changChar(UserSex);
		UserPresent = changChar(UserPresent);
		
		resp.setContentType("text/html;charset=utf-8");
		PrintWriter out = resp.getWriter();
		
		out.write("<html> <body><center> <h1>");
		out.write("  :"+UserName+"<br>");
		out.write("  :"+UserPass+"<br>");
		out.write("  :"+UserSex+"<br>");
		
		for (int i=0;i<Userfavor.length;i++){
			out.write("  :"+Userfavor[i]+"<br>");
		}
		out.write("    :"+UserPresent+"<br>");
		out.write("</h1></centen> </body> </html>");
		out.flush();

3단계, 서브렛 구성
 <servlet>
    <servlet-name>RegsiterServlet</servlet-name>
    <servlet-class>com.java.servlet.RegsiterServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>RegsiterServlet</servlet-name>
    <url-pattern>/Servlet/RegsiterServlet</url-pattern>
  </servlet-mapping>

4단계, 테스트...

좋은 웹페이지 즐겨찾기