programming/spring_framework

Spring Controller에서 뷰(JSP) 페이지로 값 넘기기

labj 2012. 3. 21. 12:27

* 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>