Spring에서 Simpleformbankingobject

JSP에서 데이타를 입력해서 보여주는게 아니라. Action에서 데이터를 제공해 주는 것으로 데이타를 보호 할 수 있다.

- IndexAction.java

package person.actions;

import java.util.List;
import java.util.ArrayList;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class IndexAction extends ActionSupport {
 
 private List<String> list;
 
 @Override
 public String execute()throws Exception {
  list = new ArrayList<String>();
  list.add("서울");
  list.add("부산");
  list.add("대구");
  list.add("대전");
  list.add("광주");
  list.add("인천");
  list.add("울산");
  return SUCCESS;
 }
 
 public List<String> getList(){
  return list;
 }

}

* list에있는 서울, 부산, 대구, 대전, 광주, 인천, 울산 데이터를 JSP 페이지에 보여줄 것이다.

- write.jsp

<%@ page language="java"
         contentType="text/html; charset=EUC-KR"
         pageEncoding="EUC-KR"%>
<%@ taglib prefix="s" uri="/struts-tags"%>        
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>struts2::interceptor</title>
<style type="text/css">
     td {font-size: 11pt; text-decoration: none; color: #000000}
    </style>
</head>
<body>
  <center>
    <br /><br />
    <h3><b>struts2 interceptor(checkbox)</b></h3>
    <form method="post" name="myform" action="write.action">
      <table border=0 cellpadding=0 cellspacing=1
             bgcolor="#000000">
        <tr height=30 bgcolor="#ffffff">
          <td bgcolor="#f0f0f0" width=100 align="center">성명</td>
          <td width=300 align="left">&nbsp;
            <input type="text" name="name">
          </td>
        </tr>    
        <tr height=30 bgcolor="#ffffff">
          <td bgcolor="#f0f0f0" width=100 align="center">이메일</td>
          <td width=300 align="left">&nbsp;
            <input type="text" name="email">
          </td>
        </tr> 
        <tr height=30 bgcolor="#ffffff">
          <td bgcolor="#f0f0f0" width=100 align="center">주소</td>
          <td width=300 align="left">&nbsp;
            <select name="addr">
              <s:iterator value="list">
                <option value="<s:property />">
                  <s:property/>
                </option>
              </s:iterator>
            </select>
          </td>
        </tr> 
        <tr height=30 bgcolor="#ffffff">
          <td bgcolor="#f0f0f0" width=100 align="center">취미</td>
          <td width=300 align="left">&nbsp;
            <input type="checkbox" name="travel" value="여행" checked>여행
            <input type="checkbox" name="climbing" value="등산" >등산
            <input type="checkbox" name="game" value="게임">게임
          </td>
        </tr>
        <tr height=30 bgcolor="#ffffff">
          <td bgcolor="#f0f0f0" width=100 align="center">성별</td>
          <td width=300 align="left">&nbsp;
            <input type="radio" name="sex" value="남" checked>남
            <input type="radio" name="sex" value="여">여
          </td>
        </tr>
        <tr height=30 bgcolor="#f0f0f0">
          <td align="right" colspan=2>
            <input type="submit" value="등록...">&nbsp;
          </td>
        </tr>
      </table>       
    </form>
  </center>
</body>
</html>

* 아래 부분에서 IndexAction.java 의 리스트 부분의 데이타를 보여 줄 수 있다.

<select name="addr">
    <s:iterator value="list">
           <option value="<s:property />">
              <s:property/>
           </option>
      </s:iterator>
 </select>

+ Recent posts