태터데스크 관리자

도움말
닫기
적용하기   첫페이지 만들기

태터데스크 메시지

저장하였습니다.


'webwork'에 해당되는 글 8건

  1. 2008/05/14 [webwork] xwork.xml에서 하나의 action에 default method설정하는 법
  2. 2008/04/12 webwork.properties때문에 404에러 삽질...
  3. 2008/03/03 [Spring] Annotation을 이용한 Spring과 Webwork Action간의 Injection (2)
  4. 2008/01/01 webwork.properties 전체 내용
  5. 2008/01/01 webwork.properties 설정 관련 (DefaultActionMapper 재설정 포함)
  6. 2008/01/01 webwork 초기 셋팅
  7. 2007/12/27 Struts의 Action과 Webwork의 Action의 차이점!
  8. 2007/12/23 webwork를 이용하기 위한 최소 lib
2008/05/14 17:55

[webwork] xwork.xml에서 하나의 action에 default method설정하는 법

<action name="list" class="tester.action.TesterEntryInfoAction" method="list">
   <result name="list">/tester/entryinfo/list.jsp</result>
  </action>
  <action name="detail" class="tester.action.TesterEntryInfoAction" method="detail">
   <result name="detail">/tester/entryinfo/detail.jsp</result>
  </action>
  <action name="addmodify" class="tester.action.TesterEntryInfoAction" method="addmodify">
   <result name="detail">/tester/entryinfo/detail.jsp</result>
  </action>
Trackback 0 Comment 0
2008/04/12 01:45

webwork.properties때문에 404에러 삽질...

webwork.action.extension=do
여긴 webwork.properties



 <servlet>
  <servlet-name>webwork</servlet-name>
  <servlet-class>
   com.opensymphony.webwork.dispatcher.ServletDispatcher
  </servlet-class>
 </servlet>
 <servlet-mapping>
  <servlet-name>webwork</servlet-name>
  <url-pattern>*.do</url-pattern>
 </servlet-mapping>
이건... web.xml


내 플젝 웹 호스팅 해주는 곳에서 어느 순간 .do만 tomcat으로 가게 아파치 설정을 변경한 듯 하다...

원래 .trust 를 사용하고 있었는데... 어느 순간 아파치 404에러...-_-;;;

.do로 해보니 tomcat으로 가긴 가나보다. tomcat 404에러...

web.xml에서 webwork로 가는 uri를 .trust에서 .do로 변경하였다.

한데... webwork로 가질 않고 계속 404에러가 발생한다.

문제는 위에 webwork.properties에서 webwork.action.extension=trust 로 되어 있었던 것...

-_-;;;  왜 두군데나 설정을 해줘야 하는거야~!!!!
Trackback 0 Comment 0
2008/03/03 14:45

[Spring] Annotation을 이용한 Spring과 Webwork Action간의 Injection

Spring는 Webwork와 연동이 된다.

하지만 Spring의 IoC를 이용하려면 Auto wire를 이용해야만 한다.

applicationContext*.xml에서 지정해서 사용할 수 없다는 뜻이 되겠다.

좀 더 자세히 설명하자면 Spring은 Webwork의 Action이 만들어 질때

BO같은 서비스 객체들을 생성할때 Spring의 Auto wire(자동으로 Injection되는)를 사용해야만 한다는 뜻이다.

이건 좀 맘에 안들어 다른 방법을 알아보았다.


Inject.java

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface Inject {
       public String beanId();
}

이렇게 만들어 줌으로 인해...

아래와 같이 Action에서 Annotation을 지정해 줄 수 있다.

public class AccountMgrAction extends UserBaseAction {
   private AccountService accountService;

  @Inject(beanId="accountService")
   public void setAccountService(AccountService accountService) {
      this.accountService = accountService;
   }

...


한데 저렇게만 해준다고 Injection이 되는건 아니다... 당연히 구현해준게 하나도 없으니...

현재는 일단은 @Inject를 사용할 수 있다는 것이다.


이제 Injection해주는 부분을 구현해 주어야 한다.

Webwork의 interceptor부분에 넣어줄껀데... interceptor는 Action이 실행되기 전, 후에 실행되는 Class이다.

AOP의 개념이 좀 들어간 그런 클래스이다.

InjectInterceptor.java
public class InjectInterceptor implements Interceptor
    // public만 리턴된다.
    Method[] methods = invocation.getAction().getClass().getMethods();

    for(Method method : methods)
    {
        doInject(invocation.getAction(), method);
    }



    private void doInject(Object action, Method method) throws Exception
    {
         Inject injectAnnotation = method.getAnnotation(Inject.class);
          Object bo = SpringBeanFactory.getBean(injectAnnotation.beanId());
         method.invoke(action, new Object[] {bo});
        //여기서 Annotation이 선언된 action클래스의 setter메소드가 실행이 되어 bo가
        //셋팅되는 것이다.

    }

...

이렇게 되면 Action이 호출되면....

그 전에 Interceptor(InjectInterceptor)가 실행이 되어 해당 Action의 Annotation을 파악하여

해당 setter에 bo객체를 Injection해주게 된다. 그리고 나서 Action이 실행되게 되므로...

Annotation을 이용해서 Injection을 하게 된다.

중요한건 Bo는 applicationContext*.xml에 bo나 dao같은 객체는 정의가 되어있어야 한다.

그래야 SpringBeanFactory.getBean(..)으로 가져올 것 아닌가...

Trackback 0 Comment 2
  1. anarch 2008/05/07 17:45 address edit & del reply

    좋은 글 잘 읽었습니다~ :-)
    이번 프로젝트에서 ww을 써야 해서 IOC Container을 어찌 할까 고민이 많았는데.
    많은 도움이 될거 같네요. :-)
    (Spring 2.5 의 annotation으로 하다가 xml configuraion을 하려니까 일이 많아지는거 같아서요..;;)
    그럼 즐거운 하루 되시기를.. :-)

2008/01/01 18:08

webwork.properties 전체 내용

### Webwork default properties
###(can be overridden by a webwork.properties file in the root of the classpath)
###

### Specifies the Configuration used to configure webwork
### one could extend com.opensymphony.webwork.config.Configuration
### to build one's customize way of getting the configurations parameters into webwork
# webwork.configuration=com.opensymphony.webwork.config.DefaultConfiguration

### This can be used to set your default locale and encoding scheme
# webwork.locale=en_US
webwork.i18n.encoding=UTF-8

### if specified, the default object factory can be overridden here
### Note: short-hand notation is supported in some cases, such as "spring"
###       Alternatively, you can provide a com.opensymphony.xwork.ObjectFactory subclass name here 
# webwork.objectFactory = spring

### specifies the autoWiring logic when using the SpringObjectFactory.
### valid values are: name, type, auto, and constructor (name is the default)
webwork.objectFactory.spring.autoWire=name

### indicates to the webwork-spring integration if Class instances should be cached
### this should, until a future Spring release makes it possible, be left as true
### unless you know exactly what you are doing!
### valid values are: true, false (true is the default)
webwork.objectFactory.spring.useClassCache=true

### if specified, the default object type determiner can be overridden here
### Note: short-hand notation is supported in some cases, such as "tiger" or "notiger"
###       Alternatively, you can provide a com.opensymphony.xwork.util.ObjectTypeDeterminer implementation name here
### Note: if you have the xwork-tiger.jar within your classpath, GenericsObjectTypeDeterminer is used by default
###       To disable tiger support use the "notiger" property value here.
#webwork.objectTypeDeterminer=tiger
#webwork.objectTypeDeterminer=notiger

### Parser to handle HTTP POST requests, encoded using the MIME-type multipart/form-data
# webwork.multipart.parser=cos
# webwork.multipart.parser=pell
webwork.multipart.parser=jakarta
# uses javax.servlet.context.tempdir by default
webwork.multipart.saveDir=
webwork.multipart.maxSize=2097152

### Load custom property files (does not override webwork.properties!)
# webwork.custom.properties=application,com/webwork/extension/custom

### How request URLs are mapped to and from actions
webwork.mapper.class=com.opensymphony.webwork.dispatcher.mapper.DefaultActionMapper

### Used by the DefaultActionMapper
### You may provide a comma separated list, e.g. webwork.action.extension=action,jnlp,do
webwork.action.extension=action

### Used by FilterDispatcher
### If true than WW serves static content from inside its jar.
### If false than the static content must be available at <context_path>/webwork
webwork.serve.static=true

### use alternative syntax that requires %{} in most places
### to evaluate expressions for String attributes for tags
webwork.tag.altSyntax=true

### when set to true, WebWork will act much more friendly for developers. This
### includes:
### - webwork.i18n.reload = true
### - webwork.configuration.xml.reload = true
### - raising various debug or ignorable problems to errors
###   For example: normally a request to foo.action?someUnknownField=true should
###                be ignored (given that any value can come from the web and it
###                should not be trusted). However, during development, it may be
###                useful to know when these errors are happening and be told of
###                them right away.
webwork.devMode=false

### when set to true, resource bundles will be reloaded on _every_ request.
### this is good during development, but should never be used in production
webwork.i18n.reload=false

### Standard UI theme
### Change this to reflect which path should be used for JSP control tag templates by default
webwork.ui.theme=xhtml
webwork.ui.templateDir=template
#sets the default template type. Either ftl, vm, or jsp
webwork.ui.templateSuffix=ftl

### Configuration reloading
### This will cause the configuration to reload xwork.xml when it is changed
webwork.configuration.xml.reload=false

### Location of velocity.properties file.  defaults to velocity.properties
# webwork.velocity.configfile=velocity.properties

### Comma separated list of VelocityContext classnames to chain to the WebWorkVelocityContext
# webwork.velocity.contexts=

### used to build URLs, such as the UrlTag
webwork.url.http.port=80
webwork.url.https.port=443

### possible values are: none, get or all
webwork.url.includeParams=get

### Load custom default resource bundles
# webwork.custom.i18n.resources=testmessages,testmessages2

### workaround for some app servers that don't handle HttpServletRequest.getParameterMap()
### often used for WebLogic, Orion, and OC4J
webwork.dispatcher.parametersWorkaround=false

### configure the Freemarker Manager class to be used
### Allows user to plug-in customised Freemarker Manager if necessary
### MUST extends off com.opensymphony.webwork.views.freemarker.FreemarkerManager
#webwork.freemarker.manager.classname=com.opensymphony.webwork.views.freemarker.FreemarkerManager

### See the WebWorkBeanWrapper javadocs for more information
webwork.freemarker.wrapper.altMap=true

### configure the XSLTResult class to use stylesheet caching.
### Set to true for developers and false for production.
webwork.xslt.nocache=false

### insert Freemarker's Sitemesh applydecorator transform to be put
### into freemarker's model allowing sitemesh's applydecorator tag to
### be used in freemarker's page eg.
### <@sitemesh.applydecorator name="someDecorator" page="/pages/somePage.ftl" />
#
webwork.freemarker.sitemesh.applyDecoratorTransform=true

### A start up listener class name (must implements com.opensymphony.webwork.dispatcher.StartUpListener
### interface) that will get invoked only once when WebWork started up. The class names could be
### comma separated and will be executed in order.
#
#webwork.dispatcher.startUpListener=foo.bar.StartUpListener1,foo.bar.StartUpListener2

### A shut down listener class name (must implements com.opensymphony.webwork.dispatcher.ShutDownListener
### interface) that will get invoked only once when WebWork shuts down.  The class names could be
### comma separated and will be executed in order.
#
#webwork.dispatcher.shutDownListener=foo.bar.ShutDownListener1,foo.bar.ShutDownListener2
Trackback 0 Comment 0
2008/01/01 18:03

webwork.properties 설정 관련 (DefaultActionMapper 재설정 포함)

webwork.i18n.encoding=UTF-8

webwork.action.extension=trust
webwork.tag.altSyntax=false
webwork.configuration.xml.reload=true

webwork.mapper.class=kr.trust.moneyplanner.web.mapper.DispatchActionMapper
kr.trust.webwork.mapper.methodParameter=m

webwork.ui.theme=simple


webwork.properties 파일의 내용이다.
붉은 글씨로 표시된 부분이 직접 구현할 내용이 되겠다.

구현하게 되면...

http://localhost/MoneyPlanner/acc.action?m=list
http://localhost/MoneyPlanner/acc.action?m=regist
위와 같이 m이라는 파라미터를 통해 같은 Action내에 실행되는 메소드가 다르게 설정해줄 수 있다.
Struts의 DispatchAction을 상속받은 Action과 같은 기능이다.

package kr.trust.moneyplanner.web.mapper;

import static kr.trust.moneyplanner.web.WebConstants.DEFAULT_METHOD_PARAMETER;
import static kr.trust.moneyplanner.web.WebConstants.METHOD_PARAMETER_DELIM;
import static kr.trust.moneyplanner.web.WebConstants.PROP_METHOD_PARAMETER;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.opensymphony.webwork.config.Configuration;
import com.opensymphony.webwork.dispatcher.mapper.ActionMapping;
import com.opensymphony.webwork.dispatcher.mapper.DefaultActionMapper;

public class DispatchActionMapper extends DefaultActionMapper {
 protected static Log log = LogFactory.getLog(DispatchActionMapper.class);
 
 public ActionMapping getMapping(HttpServletRequest request)
 {
  String methodParameter = null;
  ActionMapping mapping = super.getMapping(request);
 
  if(mapping == null)
   return null;
 
  try {
   // webwork.properties파일에 kr.trust.webwork.mapper.methodParameter로 설정되어 있는 값(m)
   methodParameter = (String)Configuration.get(PROP_METHOD_PARAMETER);
  }
  catch(IllegalArgumentException e)
  {
   methodParameter = DEFAULT_METHOD_PARAMETER;
  }
 
  String methodName = getMethodName(request, methodParameter);
 
  if(StringUtils.isEmpty(methodName))
  {
   return mapping;
  }
 
  if(log.isDebugEnabled())
  {
   log.debug("method parameter detected. Setting mapping method : " + methodName);
  }
 
  mapping.setMethod(methodName);
 
  return mapping;
 }
 
 // 파라미터로 넘어온 값을 되돌려 준다. m=list라는 파라미터가 오면 methodName은 list이다.
 private String getMethodName(HttpServletRequest request, String methodParameter)
 {
  String[] methodParameters = methodParameter.split(METHOD_PARAMETER_DELIM);
  String methodName = null;
 
  for(int i = 0 ; i < methodParameters.length ; i++)
  {
   if(request.getParameter(methodParameters[i]) != null)
   {
    methodName = request.getParameter(methodParameters[i]);
    break;
   }
  }
 
  return methodName;
 }
}







package kr.trust.moneyplanner.web;

public final class WebConstants {
 private WebConstants() {}
 
 public static final String DEFAULT_METHOD_PARAMETER = "m";
 public static final String PROP_METHOD_PARAMETER = "kr.trust.webwork.mapper.methodParameter";
 public static final String METHOD_PARAMETER_DELIM = ",";
}


Trackback 0 Comment 0
2008/01/01 10:58

webwork 초기 셋팅

xwork.jar
common-logging.jar
oscore.jar : general utility from Open Sympony
velocity-dep.jar
ognl.jar : Object Graphic Navigation Language



셋팅해야 하는 파일
xwork.xml : action, result, interceptor를 설정하는 파일
web.xml

xwork.xml은 WEB-INF/classes 안에 포함되어야 한다.


web.xml 설정
<servlet>
<servlet-name>webwork</servlet-name>
<servlet-class>
com.opensymphony.webwork.dispatcher.ServletDispatcher
</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>webwork</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>

<taglib>
<taglib-uri>webwork</taglib-uri>
<taglib-location>/WEB-INF/lib/webwork-2.1.7.jar
</taglib-location>
</taglib>



xwork.xml 설정
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN"
"http://www.opensymphony.com/xwork/xwork-1.0.dtd">
<xwork>
<include file="webwork-default.xml"/>
<package name="default" extends="webwork-default">
<default-interceptor-ref name="completeStack"/>
</package>
</xwork>

webwork-default.xml파일은 꼭 include해야 한다. 새로 만들어야 하는건 아니고
webwork.jar파일에 기본적으로 포함이 되어있다.
Trackback 0 Comment 0
2007/12/27 18:30

Struts의 Action과 Webwork의 Action의 차이점!

  • Struts
    • Singleton - Action 인스턴스는 단 하나만 존재. 따라서 thread-safe 하게 구현해야 함.
    • Servlet API 에 종속적임 (HttpServletRequest, HttpServletResponse 를 직접적으로 사용)
  • WebWork
    • None-Singleton - 매 reqeust 마다 객체가 새로 생성됨. thread-safe 일 필요가 없음.
    • Servlet API 에 종속적이지 않으며 POJO 기반.

'Framework' 카테고리의 다른 글

Struts의 Action과 Webwork의 Action의 차이점!  (0) 2007/12/27
webwork를 이용하기 위한 최소 lib  (0) 2007/12/23
Quartz  (0) 2007/12/20
Trackback 0 Comment 0
2007/12/23 14:41

webwork를 이용하기 위한 최소 lib

webwork.jar
xwork.jar
oscore.jar
ognl.jar
commons-logging.jar
freemarker.jar
web.xml

출처 : Tong - 굿보이군님의 JAVA통

'Framework' 카테고리의 다른 글

Struts의 Action과 Webwork의 Action의 차이점!  (0) 2007/12/27
webwork를 이용하기 위한 최소 lib  (0) 2007/12/23
Quartz  (0) 2007/12/20
Trackback 0 Comment 0