2008-10-28 3 views
3

Groovlet을 Grails 앱에 드롭하려면 어떻게해야합니까? 당신이 그루비 스크립트를 지원하는 서블릿 컨테이너있을 때 나는 그것을 이해하는 방법은, groovlets를 사용하는Grails 앱의 Groovlet

 
import java.util.Date 

if (session == null) { 
    session = request.getSession(true); 
} 

if (session.counter == null) { 
    session.counter = 1 
} 

println """ 
<html> 
    <head> 
     <title>Groovy Servlet</title> 
    </head> 
    <body> 
Hello, ${request.remoteHost}: Counter: ${session.counter}! Date: ${new Date()} 
<br> 
""" 

답변

6
  1. grails install-templates
  2. 편집 src/templates/web/web.xml
  3. grails war
  4. 내가 개인적으로 groovlet을 통합하기 위해 이런 짓을하지했습니다

배포하여 groovlet을 포함, 그러나 이것은 수정하는 문서화 된 방법입니다하기 전개 된 Grails web.xml

+0

니스! 나는 그것을 몰랐다. Groovlet을 사용하는 것은 컨트롤러와 뷰를 추가하는 MVC 방식과 달리 해킹으로 간주되는 것으로 생각하십니까? 아니면 괜찮습니까? – kolrie

+0

Groovlet이 이미 프로덕션 앱에 포함되어 있거나 잘 테스트 된 경우 위에서 설명한대로 그루 블렛을 포함합니다. Groovlet이 사소하거나 Grails 컨트롤러 (물론 테스트 포함)에 쉽게 포팅 될 수 있다면 포트는 계속 가치가있을뿐 아니라 연속성을 유지하는 데 충분할 것입니다. –

0

,

내가 Grails는 당신이하고자 생각 예를 들어, 웹 응용 프로그램에서/groovlet.groovy, 말 비즈니스 로직 코드를 controller으로 옮기고 HTML 또는 GSP file으로보기 파트를 남겨 두어야합니다. 그 라인 (내 머리의 상단에서 메타 코드, 테스트하지)를 따라

뭔가 :

Grails의-응용 프로그램/컨트롤러/SampleController.groovy

class DateController { 
    def index = { 
     if (session == null) { 
      session = request.getSession(true); 
     } 

     if (session.counter == null) { 
      session.counter = 1 
     } 
    } 
} 

웹 응용 프로그램/샘플/색인 .gsp

<html> 
    <head> 
    <title>Groovy Servlet</title> 
    </head> 
    <body> 
Hello, ${request.remoteHost}: Counter: ${session.counter}! Date: ${new Date()} 
<br> 

희망 하시겠습니까?

관련 문제