사용자 도구

사이트 도구


groovy:groovlet

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
groovy:groovlet [2012/09/05 15:32]
kwon37xi
groovy:groovlet [2012/09/07 11:10] (현재)
kwon37xi
줄 16: 줄 16:
  
   * 서블릿 ''*.groovy'' 파일 경로 : ''webapps/*'' 혹은 ''webapps/WEB-INF/groovy/*'' 다중 디렉토리 구조 가능. 호출은 해당 위치 기준으로 웹브라우저에서 ''/directory/filename.groovy'' 형태로 한다.   * 서블릿 ''*.groovy'' 파일 경로 : ''webapps/*'' 혹은 ''webapps/WEB-INF/groovy/*'' 다중 디렉토리 구조 가능. 호출은 해당 위치 기준으로 웹브라우저에서 ''/directory/filename.groovy'' 형태로 한다.
 +  * ''/WEB-INF/lib''에 groovy-all-*.jar 를 넣어두어야 한다.
   * 기타 groovy 라이브러리성 파일들은 ''webapps/WEB-INF/classes'' 에 패키지 구조 그대로 넣으면 된다.   * 기타 groovy 라이브러리성 파일들은 ''webapps/WEB-INF/classes'' 에 패키지 구조 그대로 넣으면 된다.
 +
  
 ===== 기본 내장 객체 목록 ===== ===== 기본 내장 객체 목록 =====
줄 45: 줄 47:
 </code> </code>
  
- +  * contextPath : ''context.contextPath''
 ===== session ===== ===== session =====
 세션 사용시 주의해야 한다. session 내장 객체가 null 일수 있기 때문이다. 세션 사용시 주의해야 한다. session 내장 객체가 null 일수 있기 때문이다.
줄 98: 줄 99:
   * ''<% out << 평가식 %>'' : 평가결과 출력   * ''<% out << 평가식 %>'' : 평가결과 출력
   * ''$평가식'' : 평가 결과 출력   * ''$평가식'' : 평가 결과 출력
 +
 +===== 사용자 정의 내장 객체 넣기 =====
 +GroovyServlet과 TemplateServlet을 상속받아서 [[http://groovy.codehaus.org/api/groovy/servlet/AbstractHttpServlet.html#setVariables%28groovy.servlet.ServletBinding%29|protected void setVariables()]] 를 Override한 뒤에 ServetletBinding 객체에 자신이 원하는 객체를 더 넣어주면 Groovlet과 Template에서 내장 객체로 사용할 수 있다.
 +
 +web.xml 에서 servlet-mapping 등록은 자신이 만든 클래스로 변경해줘야 한다.
 +<code java>
 +public class LogViewerTemplateServlet extends TemplateServlet {
 +
 + private static final long serialVersionUID = 1L;
 +
 + @Override
 + protected void setVariables(ServletBinding binding) {
 + HttpServletRequest request = (HttpServletRequest)binding.getVariable("request");
 + HttpServletResponse response = (HttpServletResponse)binding.getVariable("response");
 + ServletContext context = (ServletContext)binding.getVariable("context");
 +
 + binding.setVariable("ht", new HtmlTools(context, request, response));
 + }
 +}
 +
 +</code>
 +
 +
  
groovy/groovlet.1346826774.txt.gz · 마지막으로 수정됨: 2012/09/05 15:32 저자 kwon37xi