note

struts2 네임스페이스 사용 본문

카테고리 없음

struts2 네임스페이스 사용

투한 2012. 2. 21. 10:38








파일 위치






struts.xml
<!-- 3. 네임스페이스 사용 -->
	<package name="ch4" namespace="/ch4" extends="struts-default">
		<action name="helloWorld03" class="com.ch4.action.HelloWorld">
			<result name="success">/ch4/hello.jsp</result>
		</action>
	</package>


HelloWorld.java
package com.ch4.action;

import com.opensymphony.xwork2.Action;

public class HelloWorld implements Action{

	private String message;
	
	//struts2 시스템에서 getMessage()를 호출한다
	public String getMessage() {
		return message;
	}

	@Override
	public String execute() throws Exception {
		message ="몽롱한 화요일";
		return SUCCESS;
	}

}



hello.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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>네임스페이스 사용</title>
</head>
<body>
${message}
</body>
</html>

대문자 SUCESS는 소문자 sucess를 return함