note

struts2 OGNL 표기 Append / Merge / Date 본문

JSP/Struts2

struts2 OGNL 표기 Append / Merge / Date

투한 2012. 2. 23. 11:31









struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
	<package name="ch7" namespace="/ch7" extends="struts-default">
		<!-- 와일드 카드 매핑사용 -->
		<action name="*" class="com.ch7.action.{1}Action">
			<interceptor-ref name="params" />
			<result name="success">/ch7/{1}.jsp</result>
		</action>
	</package>
</struts>


AppendAction.java / MergeAction.java
package com.ch7.action;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.Action;

public class AppendAction implements Action{

	List<String> myList1;
	List<String> myList2;
	
	
	@Override
	public String execute() throws Exception {
		myList1 = new ArrayList<String>();
		myList1.add("a");
		myList1.add("b");
		
		myList2 = new ArrayList<String>();
		myList2.add("1");
		myList2.add("2");
		
		return SUCCESS;
	}
	public List<String> getMyList1() {
		return myList1;
	}
	public List<String> getMyList2() {
		return myList2;
	}
	
}



Append.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ 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=UTF-8">
<title>Append Test</title>
</head>
<body>
<h3>append Test</h3>
<s:append id="appendList">
	<s:param value="%{myList1}"/>
	<s:param value="%{myList2}"/>
</s:append>
<p>${appendList}</p>
<!-- EL표기법 forEach와 같다 변수지정을 안했기에 property도 그냥 쓰면 뽑아냄 -->
<s:iterator value="%{appendList}">
	<s:property />
	<br/>
</s:iterator>
</body>
</html>


Merge.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ 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=UTF-8">
<title>Merge Test</title>
</head>
<body>
<h3>Merge Test</h3>
<s:merge id="mergeList">
	<s:param value="%{myList1}" />
	<s:param value="%{myList2}" />
</s:merge>
<p>${mergeList}</p>
<s:iterator value="%{mergeList}">
	<s:property/>
	<br/>
</s:iterator>
</body>
</html>






Date  날짜







DateAction.java
package com.ch7.action;

import java.util.Date;

import com.opensymphony.xwork2.Action;

public class DateAction implements Action{

	private Date now;

	@Override
	public String execute() throws Exception {
		now = new Date();
		return SUCCESS;
	}
	public Date getNow() {
		return now;
	}
}



Date.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ 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=UTF-8">
<title>Date Test</title>
</head>
<body>
<s:date name="now" format="yyyy년MM월dd일E요일 a hh:mm:ss"/>
</body>
</html>





SimpleDateFormat과 같다