Tag Archives: Struts2

[Struts2] Jsp 페이지에서 session 변수에 접근

Struts2: Accessing Session Variables in JSP’s
참조: http://j2eewebprogrammer.blogspot.com/2009/06/struts2-accessing-session-variables-in.html

Struts 2 places named objects including the session onto the OGNL stack.
Struts2는 session을 포함한 named objects를 OGNL 스텍에 놓는다.

Action:
 extends ActionSupport implements SessionAware

  setSession("user", user);

JSP:
<s:property value="%{#session.user.firstName}"/>
Request parameter : #parameters['attrName ']
Request attribute : #request.attrName 
Session attribute : #session.attrName
Application Attribute : #application.attrName

[struts2] if test enum OR

public enum Location {
	FRONT(1),
	FORUM(2),
	TOPIC(4),
	VIEW(8),
	TAG(16);
	
	private int num;
	
	Location(int  num) {
		this.num = num;
	}
	
	public int getNum(){
		return num;
	}
}

Location location = Location.TOPIC;

	<s:if test='%{location.toString() == "TOPIC"}'>
		<s:set var="h2" value="%{getText('Reply')}"/>
	</s:if>
	<s:elseif test='%{location.toString() == "FORUM"}'>
		<s:set var="h2"  value="%{getText('New Topic in this Forum')}"/>
	</s:elseif>
	<s:elseif test='%{location.toString() == "TAG"  || location.toString() == "FRONT"}'>
		<s:set var="h2" value="%{getText('Add New Topic')}"/>
	</s:elseif>