Spring Controller에서 뷰(JSP) 페이지로 값 넘기기
* List 형식으로 넘기기
- controller
HashMap<String, String> data = new HashMap<String, String>();
List<HashMap<String, String>> login = new ArrayList<HashMap<String, String>>();
data.put("id", "namju");
data.put("password", "1234");
login.add(data);
return new ModelAndView( "logins/login", "login", login);
- jsp page
<c:forEach items="${login}" var="login">
${login.id}<br>
${login.password}<br>
</c:forEach>
* domain 객체에 값을 설정하여 넘기기
- domain
package kr.actsoft.dlms.login.domain;
import java.util.List;
import kr.actframeworks.commons.BaseObject;
public class Login extends BaseObject {
private String id;
private String password;
public Login() {
super();
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
- controller
Login login = new Login();
login.setId("namju");
login.setPassword("1234");
return new ModelAndView( "logins/login", "login", login);
- jsp page
${login.id}<br>
${login.password}<br>
* domain 객체에 String, List 객체를 넣어서 값 넘기기
- domain
package kr.actsoft.dlms.login.domain;
import java.util.List;
import kr.actframeworks.commons.BaseObject;
public class Login extends BaseObject {
private String id;
private String password;
private List list;
public Login() {
super();
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public void setList(List list) {
this.list = list;
}
public List getList() {
return list;
}
}
- controller
Login login = new Login();
login.setId("namju");
login.setPassword("1234");
HashMap<String, String> data = new HashMap<String, String>();
List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
data.put("id", "namju");
data.put("password", "9994");
list.add(data);
login.setList(list);
- jsp page
${login.id}<br>
${login.password}<br>
<c:forEach items="${login.list}" var="list">
${list.id}<br>
${list.password}<br>
</c:forEach>
'차근차근 > JAVA JSP' 카테고리의 다른 글
[servlet] error 메세지와 redirect, 응답코드 / Dispatcher를 이용해서 forward~!!(서블릿 혹은 JSP) (0) | 2014.07.26 |
---|---|
RequestDispatcher dispatcher = request.getRequestDispatcher (0) | 2014.07.26 |
webview , popup창 (0) | 2014.07.26 |
[JAVA] 자바로 사진(JPEG) 메타데이터[사진정보, GPS] 가져오기 (0) | 2014.07.25 |
[JAVA] 상대경로로 Jar 파일 추가하기 (0) | 2014.07.25 |