문제

Groovlet을 Grails 앱에 어떻게 삭제합니까? 예를 들어 Web-App/Groovlet.groovy에서

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>
"""

도움이 되었습니까?

해결책

  1. grails install-templates
  2. 편집하다 src/templates/web/web.xml groovlet을 포함합니다
  3. grails war
  4. 배포

나는 그루 글을 통합하기 위해 개인적으로 이것을하지 않았지만 이것은 배치 된 성배를 수정하는 문서화 된 방법입니다. web.xml

다른 팁

내가 이해하는 방식은 그루비 스크립팅 지원이있는 서블릿 컨테이너가있을 때 그루 클릿이 사용됩니다.

성배에서 비즈니스 로직 코드를 제어 장치 뷰 부분을 HTML 또는 GSP 파일.

그 라인을 따라 무언가 (내 머리 꼭대기에서 메타 코드, 테스트되지 않은 메타 코드) :

Grails-App/컨트롤러/SampleController.groovy

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

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

Web-App/Sample/Index.gsp

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

도움이되기를 바랍니다!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top