2.3 Your first action

2.3.1 Saying hello, the WebWork way

  • HelloWorld.java

package com.oracleclub.study.xwork;

import com.opensymphony.xwork.Action;

public class HelloWorld implements Action {

    private String message;

    public String execute() {

	message = "Hello, World!\n";
	message += "The time is:\n";
	message += System.currentTimeMillis();

	return SUCCESS;
    }

    public String getMessage() {
 	return message;
    }
}

2.3.2 Displaying output to the web browser

  • /xwork/hello.jsp

<%@ taglib prefix="ww" uri="webwork" %>

<html>
<head>
<title>Hello Page</title>
</head>

<body>
The message generated by my first action is:

<ww:property value="message"/>

</body>
</html>

2.3.3 Configuring your new action

  • xwork.xml 설정
  • xwork.xml에 설정을 하지 않고 webwork-study.xml 설정파일을 추가로 만들어서 webwork환경 설정을 하였다.

<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN"
            "http://www.opensymphony.com/xwork/xwork-1.0.dtd">

<xwork>

    <include file="/resources/webwork/webwork-default.xml"/>

    <!-- webwork-study.xml 에 설정 하였음 -->
    <include file="/resources/webwork/webwork-study.xml"/>
	
</xwork>

  • webwork-study.xml

<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.1.1//EN" "http://www.opensymphony.com/xwork/xwork-1.1.1.dtd">

<xwork>

    <package name="study" extends="webwork-default">
		
        <action name="helloWorld" class="com.oracleclub.study.xwork.HelloWorld">
            <result name="success">/xwork/hello.jsp</result>
        </action>
		
    </package>
	
</xwork>

문서에 대하여

  • 이 문서의 내용은 Webwork In Action 교재를 스터디 하면서 정리한 내용 입니다.
  • 최초작성자 : 김정식
  • 최초작성일 : 2007년 9월 13일
  • 이 문서는 오라클클럽 자바 웹개발자 스터디 모임에서 작성하였습니다.
  • 이 문서를 다른 블로그나 홈페이지에 퍼가실 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^