728x90
1. sumbit ์ผ๋ก jspํ์ด์ง์์ ๋ฐ๋ก ์ถ๋ ฅ
insert.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert</title>
</head>
<body>
<form action = "insertAf.jsp">
์์ด๋:<input type="text" name = "idp"><br>
ํจ์ค์๋:<input type="text" name = "pass"><br><br>
<p>์ทจ๋ฏธ</p>
<input type ="checkbox" name = "hobby" value = "sleep">์ ์๊ธฐ
<input type ="checkbox" name = "hobby" value = "sing">๋
ธ๋ํ๊ธฐ
<input type ="checkbox" name = "hobby" value = "game">๊ฒ์ํ๊ธฐ
<br><br>
<p>์ฐ๋ น๋</p>
<input type ="radio" name = "age" value = "10">10๋
<input type ="radio" name = "age" value = "20">20๋
<input type ="radio" name = "age" value = "30">30๋
<input type ="radio" name = "age" value = "40">40๋
<input type ="radio" name = "age" value = "50">50๋
<input type ="radio" name = "age" value = "60">60๋์ด์
<br><br>
<p>๊ธฐํํ๊ณ ์ถ์๋ง</p>
<textarea rows="10" name = "speak" cols ="30"></textarea><br><br>
<input type="submit" value = "์ ์ก">
<input type="reset" value = "์ทจ์">
</form>
</body>
</html>
insertAf.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<%
String name = request.getParameter("id");
String password = request.getParameter("pass");
String hobby[] = request.getParameterValues("hobby");
String age = request.getParameter("age");
String Box = request.getParameter("speak");
%>
</head>
<body>
<h3>์ ์ก๋ ์ ๋ณด</h3>
์์ด๋:<%= name %><br>
ํจ์ค์๋:<%= password %><br>
<%
for(int i = 0; i<hobby.length; i++){
%>
์ทจ๋ฏธ: <%=hobby[i] %><br>
<%
}
%>
์ฐ๋ น๋:<%= age %><br>
์์ธ๋ด์ญ:<%= Box %><br>
<%-- <%//์๋ฐ ์ฝ๋๋ฅผ ์ธ ์ ์๋ฐ
//java ์์ญ
out.println("์์ด๋ : " + name +"<br>");
out.println("ํจ์ค์๋ : " + password +"<br>");
if(hobby != null){
for(int i = 0; i<hobby.length; i++){
out.println("์ทจ๋ฏธ : " + hobby[i] +"<br>");
}
}
out.println("๋์ด : " + age+"<br>");
out.println("์์ธ๋ด์ญ : " + Box +"<br>");
//dao,dto
%> --%>
</body>
</html>
2. dto, setAttribute ์ฌ์ฉํ์ฌ ๋ฐ์ดํฐ ์ ์ก
teach.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action = "teach2.jsp">
์์ด๋:<input type="text" name = "idp"><br>
ํจ์ค์๋:<input type="password" name = "pass"><br><br>
<p>์ทจ๋ฏธ</p>
<input type ="checkbox" name = "hobby" value = "sleep">์ ์๊ธฐ
<input type ="checkbox" name = "hobby" value = "sing">๋
ธ๋ํ๊ธฐ
<input type ="checkbox" name = "hobby" value = "game">๊ฒ์ํ๊ธฐ
<br><br>
<p>์ฐ๋ น๋</p>
<input type ="radio" name = "age" value = "10">10๋
<input type ="radio" name = "age" value = "20">20๋
<input type ="radio" name = "age" value = "30">30๋
<input type ="radio" name = "age" value = "40">40๋
<input type ="radio" name = "age" value = "50">50๋
<input type ="radio" name = "age" value = "60">60๋์ด์
<br><br>
<p>๊ธฐํํ๊ณ ์ถ์๋ง</p>
<textarea rows="10" name = "speak" cols ="30"></textarea><br><br>
<input type="submit" value = "์ ์ก">
<input type="reset" value = "์ทจ์">
</form>
</body>
</html>
teach2.jsp
<%@page import="dto.Human"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String name = request.getParameter("idp");
String password = request.getParameter("pass");
String hobby[] = request.getParameterValues("hobby");
int age = Integer.parseInt(request.getParameter("age"));
String Box = request.getParameter("speak");
Human human = new Human(name,password,hobby,age,Box);
request.setAttribute("human", human);
//๊ฐ์ฒด๋ฅผ ๋ง๋ค์ด์ ์ด๋ํด์ค๋ค
pageContext.forward("insertAF1.jsp");
%>
dto
package dto;
import java.io.Serializable;
import java.util.Arrays;
public class Human implements Serializable{
private String id;
private String pwd;
private String hobby[];
private int age;
private String message;
public Human() {
super();
// TODO Auto-generated constructor stub
}
public Human(String id, String pwd, String[] hobby, int age, String message) {
super();
this.id = id;
this.pwd = pwd;
this.hobby = hobby;
this.age = age;
this.message = message;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public String[] getHobby() {
return hobby;
}
public void setHobby(String[] hobby) {
this.hobby = hobby;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
@Override
public String toString() {
return "Human [id=" + id + ", pwd=" + pwd + ", hobby=" + Arrays.toString(hobby) + ", age=" + age + ", message="
+ message + "]";
}
}
insertAF1.jsp
<%@page import="dto.Human"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
Human human = (Human)request.getAttribute("human");
System.out.println(human.toString());
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
์์ด๋:<%=human.getId()%><br>
ํจ์ค์๋:<%= human.getPwd() %><br>
<%
String hobby[] = human.getHobby();
for(int i = 0; i<hobby.length; i++){
%>
์ทจ๋ฏธ: <%=hobby[i] %><br>
<%
}
%>
์ฐ๋ น๋:<%= human.getAge() %><br>
์์ธ๋ด์ญ:<%= human.getMessage() %><br>
</body>
</html>
'๐ ์๋ฐ ์๋ฒ ํ์ด์ง JSP' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
JSP - EL ํ๊ทธ (Expression Language Tag) (0) | 2021.03.23 |
---|---|
JSP - MVC Model 1 / ๋ก๊ทธ์ธ ๊ฒ์ํ ๊ตฌ์ถ (0) | 2021.03.22 |
JSP - ํ์ด์ง ์๋ก๊ณ ์นจํ๋ฉด ํ ์ด๋ธ(<tr>) ์์ฑ + (0) | 2021.03.15 |
JSP - 1. ๋ด์ฅ๊ฐ์ฒด (Parameter) ๋ก ๋ฐ์ดํฐ ๋ฐ์ ์ ์ก (0) | 2021.03.15 |
JSP (java server page)๋? (0) | 2021.03.15 |
๋๊ธ