다양한 입력값 처리 하기

-----------------------------------------------------------------------

1. webapp 경로밑에 04.form.html 파일 생성후 아래 코드입력

 

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

<!-- <form action="param.do" method="get" target="_blank"> -->
<form action="04.param.do" method="get" target="myi">
<label>이름 </label> : 
<input type="text" name="myname" required><br>
<label>나이 </label> : 
<input type="number" name="myage" required min="1" max="120"><br>
<label>생일 </label> : 
<input type="date" name="mybirth" ><br>
<hr>
<label>전화번호 </label> : 
<input type="tel" name="myphone" pattern="\d{3}-\d{3,4}-\d{3,4}" placeholder="000-0000-0000"><br>
<label>이메일 </label> : 
<input type="email" name="myemail"><br>
<label>시간 </label> : 
<input type="time" name="mytime" min="09:00" max="18:00"><br>

<fieldset>
<legend>색상</legend>
<input type="radio" name="color" value="빨강">빨강<br>
<input type="radio" name="color" value="파랑">파랑<br>
<input type="radio" name="color" value="노랑">노랑<br>
</fieldset>

<fieldset>
<legend>취미</legend>
<input type="checkbox" name="hobby" value="골프">골프<br>
<input type="checkbox" name="hobby" value="낚시">낚시<br>
<input type="checkbox" name="hobby" value="영화">영화<br>
</fieldset>

<select name="company">
<option value="회사1">회사1</option>
<option value="회사2">회사2</option>
<option value="회사3">회사3</option>
</select>
<br>
<textarea rows="4" cols="100" name="mytxt"></textarea>
<br>
<button>확인</button>
</form>

<iframe name="myi" width="100%" height="700" frameborder="0"></iframe>
</body>
</html>

 

----------------------------------------------------------------------------------

2. webapp - WEB-INF - jsp - egovframework - example 경로에

04.paramview.jsp 파일 생성후 아래의 코드 입력

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>    
    
    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>이름 : ${myname}</h3>
<h3>나이 : ${myage}</h3>
<h3>생일 : ${mybirth}</h3>
<h3>전화번호 : ${myphone}</h3>
<h3>이메일 : ${myemail}</h3>
<h3>칼라 : ${color}</h3>
<ul>
<c:forEach var="h" items="${hobby}">
<h3><li>${h}</li></h3>
</c:forEach>
</ul>

<h3>회사 : ${company}</h3>
<h3>txt : ${mytxt}</h3>


</body>
</html>

 

--------------------------------------------------------------------------

3. 컨트롤러에 아래의 코드 추가 (MyController.java)

 

 

@RequestMapping(value = "/04.param.do", method = RequestMethod.GET)
public String param04(String myname, int myage, String mybirth, String myphone, String myemail, String color,
String[] hobby, String company, String mytxt, Model model) throws Exception {

model.addAttribute("myname", myname); // 데이터 설정.....
model.addAttribute("myage", myage);
model.addAttribute("mybirth", mybirth);
model.addAttribute("myphone", myphone);
model.addAttribute("myemail", myemail);
model.addAttribute("color", color);
model.addAttribute("hobby", hobby);
model.addAttribute("company", company);
model.addAttribute("mytxt", mytxt);

return "04.paramview"; // forward view
}

 

------------------------------------------------------------------------------------

 

4. 결과값 출력

 

http://localhost:8086/ttt/04.form.html 주소입력 이동후

 

 

 

 

 

 

ㄴ 폼에 입력 후 확인버튼을 누르면

 

 

 

결과값 출력을 확인 할수 있다.

+ Recent posts