setproperty를 *를 안쓰고 쓴다면
property이름은 객체의 변수이름을 가져와서 쓰는데 param은 form에 있는 number의 name을 쓴다


근데 *로 가져오면 form에 있는 name을 객체의 변수이름이랑 똑같이 맞춰야한다


안맞추니 null나옴

맞추면 짱구가 나온다~

<%@ 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="0614formgettersetter.jsp" method="post">
번호<input type="text" name="mno" value="1"><br>
이름<input type="text" name="name" value="짱구"><br>
아이디<input type="text" name="id" value="zzang"><br>
비번<input type="text" name="pw" value="1234"><br>
폰번<input type="text" name="phone" value="010-1111-1111"><br>
<input type="submit" value="제출">
</form>
</body>
</html>
<%@ 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>
<%
request.setCharacterEncoding("utf-8");
%>
<jsp:useBean id="mb" class="vo.Member"></jsp:useBean>
<%--
<jsp:setProperty property="mno" name="mb" param="mno"/>
<jsp:setProperty property="name" name="mb" param="names"/>
<jsp:setProperty property="id" name="mb" param="id"/>
<jsp:setProperty property="pw" name="mb" param="pw"/>
<jsp:setProperty property="phone" name="mb" param="phone"/>
--%>
<jsp:setProperty property="*" name="mb"/>
<h1>받은 데이터</h1>
<jsp:getProperty property="mno" name="mb"/>
<jsp:getProperty property="name" name="mb"/>
<jsp:getProperty property="id" name="mb"/>
<jsp:getProperty property="pw" name="mb"/>
<jsp:getProperty property="phone" name="mb"/>
</body>
</html>
package vo;
public class Member {
private int mno;
private String name;
private String id;
private String pw;
private String phone;
public Member() {}
public void setMno(int mno) {
this.mno = mno;
}
public int getMno() {
return mno;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPw() {
return pw;
}
public void setPw(String pw) {
this.pw = pw;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}
- forward로 넘겨버리기
request로 넘겨주면 setattribute한 것과 같이 되나보다..
그래서 getattribute로 받는데 이거는 bean을 set해준것과
같은 느낌이라 받을 때 bean으로 받아야하더라.. 첨에 오류남(prodname으로 적었다);;;;;;;;;;


prodname로 하니까 오류난다


bean으로 바꺼줌


스무스~
<%@ 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="0614itemBeangettersetter.jsp" method="post">
제품명 <input type="text" name="prodname" value="트랜스포머"><br>
가격 <input type="text" name="price" value="100000"><br>
설명 <input type="text" name="desc" value="옵티머스 프라임이 될 기회"><br>
<input type="submit" value="제출">
</form>
</body>
</html>
<%@ 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>
<%
request.setCharacterEncoding("utf-8");
%>
<jsp:useBean id="bean" class="vo.ItemBean" scope="request"></jsp:useBean>
<jsp:setProperty property="*" name="bean"/>
<jsp:forward page="0614action_result.jsp"></jsp:forward>
<h1>받아온 값</h1>
<%--
제품명: <jsp:getProperty property="prodname" name="bean"/><br>
가격: <jsp:getProperty property="price" name="bean"/><br>
설명:<jsp:getProperty property="desc" name="bean"/><br>
--%>
</body>
</html>
package vo;
public class ItemBean {
private String prodname;
private int price;
private String desc;
public ItemBean() {}
public String getProdname() {
return prodname;
}
public void setProdname(String prodname) {
this.prodname = prodname;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}
<%@page import="vo.ItemBean"%>
<%@ 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>
<%
ItemBean ib = (ItemBean)request.getAttribute("bean");
%>
이름: <%=ib.getProdname() %>
가격: ${bean.getPrice() }
설명: <%=ib.getDesc() %>
</body>
</html>
'JSP > 이론' 카테고리의 다른 글
el 배열로 (체크박스일 때 사용할 것) 가져오기/paramValues (0) | 2023.06.14 |
---|---|
EL (0) | 2023.06.14 |
jsp:useBean/serProperty, getProperty (0) | 2023.06.14 |
jsp:include vs include file (0) | 2023.06.13 |
jsp:forward (0) | 2023.06.13 |