我可以在component.jsp中使用方法吗?
我正试图根据Adobe网站上的一篇文章编写一个简单的服务层界面(代码头中显示的链接供参考)。当我尝试基于模板/组件加载页面时,我得到一个错误:方法[methodname]对于类型[componentname]\u jsp是未定义的。我尝试过使用更简单的单行方法,使用public和no-access修饰符,使用不同的签名和返回类型,将方法移动到调用代码上方,并且总是得到相同的结果。如果我注释掉方法名,只将代码作为花括号括起来的块包含进来,那么它就可以编译了。这在CQ/AEM v5.6.1中是不可能的,还是我做错了什么 整个代码和异常如下所示(为了简单起见,注释掉了我的各种实验版本,并省略了原始的getPath(…)方法)。提前感谢您抽出时间我可以在component.jsp中使用方法吗?,jsp,aem,Jsp,Aem,我正试图根据Adobe网站上的一篇文章编写一个简单的服务层界面(代码头中显示的链接供参考)。当我尝试基于模板/组件加载页面时,我得到一个错误:方法[methodname]对于类型[componentname]\u jsp是未定义的。我尝试过使用更简单的单行方法,使用public和no-access修饰符,使用不同的签名和返回类型,将方法移动到调用代码上方,并且总是得到相同的结果。如果我注释掉方法名,只将代码作为花括号括起来的块包含进来,那么它就可以编译了。这在CQ/AEM v5.6.1中是不可能
<%--
apipage component: implements service layer pages
see: http://blogs.adobe.com/contentmanagement/2012/08/19/how-to-integrate-with-other-web-services-without-creating-osgi-packages/
--%><%
%><%@include file="/libs/foundation/global.jsp"%>
<%@page import="org.apache.commons.httpclient.HttpClient,
org.apache.commons.httpclient.params.HttpClientParams,
org.apache.commons.httpclient.DefaultHttpMethodRetryHandler,
org.apache.commons.httpclient.methods.PostMethod,
org.json.JSONObject"
%><%@page session="false" %><%
%><%
if (request.getParameter("action") != null) {
if (request.getParameter("action").equals("getFields") &&
request.getParameter("param1") != null &&
request.getParameter("param2") != null) {
//response.setContentType("application/json");
// out.write(getPath((String)request.getParameter("param1"), (String)request.getParameter("param2"));
String str1 = "param1";
String str2 = "param2";
//out.write(getPath(str1, str2));
int i = doNothing();
}
} else {
response.setContentType("application/json");
out.write("{\"error\":\"error\"}");
}
/*public*/ int doNothing() {
return 1;
}
%>
Error during include of component '/apps/trp/components/layouts/apipage'
Error Message:
org.apache.sling.api.scripting.ScriptEvaluationException: org.apache.sling.scripting.jsp.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 24 in the jsp file: /apps/trp/components/layouts/apipage/apipage.jsp
The method doNothing() is undefined for the type apipage_jsp
21: String str1 = "param1";
22: String str2 = "param2";
23: //out.write(getPath(str1, str2));
24: int i = doNothing();
25: }
26: } else {
27: response.setContentType("application/json");
An error occurred at line: 31 in the jsp file: /apps/trp/components/layouts/apipage/apipage.jsp
Syntax error on token "int", new expected
28: out.write("{\"error\":\"error\"}");
29: }
30:
31: /*public*/ int doNothing() {
32: return 1;
33: }
34:
An error occurred at line: 31 in the jsp file: /apps/trp/components/layouts/apipage/apipage.jsp
doNothing cannot be resolved to a type
28: out.write("{\"error\":\"error\"}");
29: }
30:
31: /*public*/ int doNothing() {
32: return 1;
33: }
34:
An error occurred at line: 31 in the jsp file: /apps/trp/components/layouts/apipage/apipage.jsp
Syntax error, insert ";" to complete Statement
28: out.write("{\"error\":\"error\"}");
29: }
30:
31: /*public*/ int doNothing() {
32: return 1;
33: }
34:
An error occurred at line: 32 in the jsp file: /apps/trp/components/layouts/apipage/apipage.jsp
Void methods cannot return a value
29: }
30:
31: /*public*/ int doNothing() {
32: return 1;
33: }
34:
35: /*
Processing Info:
Page = /content/trp/en/AfrescoAPI
Resource Path = /content/trp/en/AfrescoAPI/jcr:content
Cell = apipage
Cell Search Path = apipage
Component Path = /apps/trp/components/layouts/apipage
Sling Request Progress:
0 (2013-11-14 10:41:01) TIMER_START{Request Processing}
0 (2013-11-14 10:41:01) COMMENT timer_end format is {<elapsed msec>,<timer name>} <optional message>
0 (2013-11-14 10:41:01) LOG Method=GET, PathInfo=/content/trp/en/AfrescoAPI.html
0 (2013-11-14 10:41:01) TIMER_START{ResourceResolution}
0 (2013-11-14 10:41:01) TIMER_END{0,ResourceResolution} URI=/content/trp/en/AfrescoAPI.html resolves to Resource=JcrNodeResource, type=cq:Page, superType=null, path=/content/trp/en/AfrescoAPI
0 (2013-11-14 10:41:01) LOG Resource Path Info: SlingRequestPathInfo: path='/content/trp/en/AfrescoAPI', selectorString='null', extension='html', suffix='null'
0 (2013-11-14 10:41:01) TIMER_START{ServletResolution}
0 (2013-11-14 10:41:01) TIMER_START{resolveServlet(JcrNodeResource, type=cq:Page, superType=null, path=/content/trp/en/AfrescoAPI)}
0 (2013-11-14 10:41:01) TIMER_END{0,resolveServlet(JcrNodeResource, type=cq:Page, superType=null, path=/content/trp/en/AfrescoAPI)} Using servlet /libs/foundation/components/primary/cq/Page/Page.jsp
0 (2013-11-14 10:41:01) TIMER_END{0,ServletResolution} URI=/content/trp/en/AfrescoAPI.html handled by Servlet=/libs/foundation/components/primary/cq/Page/Page.jsp
0 (2013-11-14 10:41:01) LOG Applying Requestfilters
0 (2013-11-14 10:41:01) LOG Calling filter: org.apache.sling.bgservlets.impl.BackgroundServletStarterFilter
0 (2013-11-14 10:41:01) LOG Calling filter: org.apache.sling.i18n.impl.I18NFilter
0 (2013-11-14 10:41:01) LOG Calling filter: org.apache.sling.rewriter.impl.RewriterFilter
0 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.wcm.designimporter.CanvasPageDeleteRequestFilter
0 (2013-11-14 10:41:01) LOG Calling filter: com.adobe.cq.history.impl.HistoryRequestFilter
0 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.wcm.core.impl.WCMRequestFilter
0 (2013-11-14 10:41:01) LOG Calling filter: com.adobe.granite.optout.impl.OptOutFilter
0 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.theme.impl.ThemeResolverFilter
0 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.wcm.foundation.forms.impl.FormsHandlingServlet
0 (2013-11-14 10:41:01) LOG Calling filter: org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter
0 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.wcm.mobile.core.impl.redirect.RedirectFilter
0 (2013-11-14 10:41:01) LOG RedirectFilter did not redirect (MobileUtil.isMobileResource() returns false)
0 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.wcm.core.impl.warp.TimeWarpFilter
0 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.wcm.core.impl.AuthoringUIModeServiceImpl
0 (2013-11-14 10:41:01) LOG Applying Componentfilters
0 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.personalization.impl.TargetComponentFilter
0 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.wcm.core.impl.WCMComponentFilter
0 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.wcm.core.impl.WCMDebugFilter
0 (2013-11-14 10:41:01) TIMER_START{/libs/foundation/components/primary/cq/Page/Page.jsp#0}
0 (2013-11-14 10:41:01) LOG Including resource JcrNodeResource, type=trp/components/layouts/apipage, superType=null, path=/content/trp/en/AfrescoAPI/jcr:content (SlingRequestPathInfo: path='/content/trp/en/AfrescoAPI/jcr:content', selectorString='null', extension='html', suffix='null')
0 (2013-11-14 10:41:01) TIMER_START{resolveServlet(JcrNodeResource, type=trp/components/layouts/apipage, superType=null, path=/content/trp/en/AfrescoAPI/jcr:content)}
16 (2013-11-14 10:41:01) TIMER_END{16,resolveServlet(JcrNodeResource, type=trp/components/layouts/apipage, superType=null, path=/content/trp/en/AfrescoAPI/jcr:content)} Using servlet /apps/trp/components/layouts/apipage/apipage.jsp
16 (2013-11-14 10:41:01) LOG Applying Includefilters
16 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.personalization.impl.TargetComponentFilter
16 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.wcm.core.impl.WCMComponentFilter
16 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.wcm.core.impl.WCMDebugFilter
16 (2013-11-14 10:41:01) TIMER_START{/apps/trp/components/layouts/apipage/apipage.jsp#1}
156 (2013-11-14 10:41:01) LOG SCRIPT ERROR: org.apache.sling.scripting.jsp.jasper.JasperException: Unable to compile class for JSP: //An error occurred at line: 24 in the jsp file: /apps/trp/components/layouts/apipage/apipage.jsp/The method doNothing() is undefined for the type apipage_jsp/21: String str1 = "param1";/22: String str2 = "param2";/23: //out.write(getPath(str1, str2));/24: int i = doNothing();/25: }/26: } else {/27: response.setContentType("application/json");///An error occurred at line: 31 in the jsp file: /apps/trp/components/layouts/apipage/apipage.jsp/Syntax error on token "int", new expected/28: out.write("{\"error\":\"error\"}");/29: }/30: /31: /*public*/ int doNothing() {/32: return 1;/33: }/34: ///An error occurred at line: 31 in the jsp file: /apps/trp/components/layouts/apipage/apipage.jsp/doNothing cannot be resolved to a type/28: out.write("{\"error\":\"error\"}");/29: }/30: /31: /*public*/ int doNothing() {/32: return 1;/33: }/34: ///An error occurred at line: 31 in the jsp file: /apps/trp/components/layouts/apipage/apipage.jsp/Syntax error, insert ";" to complete Statement/28: out.write("{\"error\":\"error\"}");/29: }/30: /31: /*public*/ int doNothing() {/32: return 1;/33: }/34: ///An error occurred at line: 32 in the jsp file: /apps/trp/components/layouts/apipage/apipage.jsp/Void methods cannot return a value/29: }/30: /31: /*public*/ int doNothing() {/32: return 1;/33: }/34: /35: /*/
156 (2013-11-14 10:41:01) TIMER_END{140,/apps/trp/components/layouts/apipage/apipage.jsp#1}
172 (2013-11-14 10:41:01) LOG Found processor for post processing ProcessorConfiguration: {contentTypes=[text/html],order=-1, active=true, valid=true, processErrorResponse=true, pipeline=(generator=Config(type=htmlparser, config={}), transformers=(Config(type=linkchecker, config={}), Config(type=mobile, config=JcrPropertyMap [node=node /libs/cq/config/rewriter/default/transformer-mobile, values={component-optional=true, jcr:primaryType=nt:unstructured}]), Config(type=mobiledebug, config=JcrPropertyMap [node=node /libs/cq/config/rewriter/default/transformer-mobiledebug, values={component-optional=true, jcr:primaryType=nt:unstructured}]), Config(type=contentsync, config=JcrPropertyMap [node=node /libs/cq/config/rewriter/default/transformer-contentsync, values={component-optional=true, jcr:primaryType=nt:unstructured}]), serializer=Config(type=htmlwriter, config={}))}
172 (2013-11-14 10:41:01) TIMER_END{172,Request Processing} Dumping SlingRequestProgressTracker Entries
包含组件“/apps/trp/components/layouts/apipage”时出错
错误消息:
org.apache.sling.api.scripting.scriptionEvaluationException:org.apache.sling.scripting.jsp.jasper.jaspereException:无法为jsp编译类:
jsp文件:/apps/trp/components/layouts/apipage/apipage.jsp的第24行出现错误
apipage_jsp类型的方法doNothing()未定义
21:String str1=“param1”;
22:String str2=“param2”;
23://out.write(getPath(str1,str2));
24:int i=doNothing();
25: }
26:}其他{
27:response.setContentType(“application/json”);
jsp文件:/apps/trp/components/layouts/apipage/apipage.jsp的第31行出现错误
令牌“int”上的语法错误,应为新
28:out.write(“{\”error\:\”error\“}”);
29: }
30:
31:/*public*/int doNothing(){
32:返回1;
33: }
34:
jsp文件:/apps/trp/components/layouts/apipage/apipage.jsp的第31行出现错误
没有任何内容无法解析为类型
28:out.write(“{\”error\:\”error\“}”);
29: }
30:
31:/*public*/int doNothing(){
32:返回1;
33: }
34:
jsp文件:/apps/trp/components/layouts/apipage/apipage.jsp的第31行出现错误
语法错误,请插入“;”以完成语句
28:out.write(“{\”error\:\”error\“}”);
29: }
30:
31:/*public*/int doNothing(){
32:返回1;
33: }
34:
jsp文件:/apps/trp/components/layouts/apipage/apipage.jsp的第32行出现错误
Void方法不能返回值
29: }
30:
31:/*public*/int doNothing(){
32:返回1;
33: }
34:
35: /*
处理信息:
页面=/content/trp/en/AfrescoAPI
资源路径=/content/trp/en/AfrescoAPI/jcr:content
单元格=apipage
单元格搜索路径=apipage
组件路径=/apps/trp/components/layouts/apipage
吊索请求进度:
0(2013-11-14 10:41:01)计时器开始{请求处理}
0(2013-11-14 10:41:01)注释计时器结束格式为{,}
0(2013-11-14 10:41:01)LOG Method=GET,PathInfo=/content/trp/en/AfrescoAPI.html
0(2013-11-14 10:41:01)计时器开始{ResourceResolution}
0(2013-11-14 10:41:01)TIMER_END{0,resourcesolution}URI=/content/trp/en/AfrescoAPI.html解析为Resource=JcrNodeResource,type=cq:Page,superType=null,path=/content/trp/en/AfrescoAPI
0(2013-11-14 10:41:01)日志资源路径信息:SlingRequestPathInfo:Path='/content/trp/en/AfrescoAPI',selectorString='null',extension='html',suffix='null'
0(2013-11-14 10:41:01)计时器启动{ServletResolution}
0(2013-11-14 10:41:01)计时器启动{resolveServlet(JcrNodeResource,type=cq:Page,superType=null,path=/content/trp/en/AfrescoAPI)}
0(2013-11-14 10:41:01)计时器{0,resolveServlet(JcrNodeResource,type=cq:Page,superType=null,path=/content/trp/en/AfrescoAPI)}使用servlet/libs/foundation/components/primary/cq/Page/Page.jsp
0(2013-11-14 10:41:01)计时器{0,ServletResolution}URI=/content/trp/en/AfrescoAPI.html由Servlet处理=/libs/foundation/components/primary/cq/Page/Page.jsp
0(2013-11-14 10:41:01)应用请求筛选器的日志
0(2013-11-14 10:41:01)日志调用筛选器:org.apache.sling.bgservlets.impl.BackgroundServletStarterFilter
0(2013-11-14 10:41:01)日志调用筛选器:org.apache.sling.i18n.impl.I18NFilter
0(2013-11-14 10:41:01)日志调用筛选器:org.apache.sling.rewriter.impl.RewriterFilter
0(2013-11-14 10:41:01)日志调用筛选器:com.day.cq.wcm.designimporter.CanvasPageDeleteRequestFilter
0(2013-11-14 10:41:01)日志调用筛选器:com.adobe.cq.history.impl.HistoryRequestFilter
0(2013-11-14 10:41:01)日志调用筛选器:com.day.cq.wcm.core.impl.WCMRequestFilter
0(2013-11-14 10:41:01)日志调用筛选器:com.adobe.granite.optout.impl.OptOutFilter
0(2013-11-14 10:41:01)日志调用筛选器:com.day.cq.theme.impl.ThemeResolverFilter
0(2013-11-14:10:41:01)日志调用过滤器:COM.ay.cq.WCM.Fuff.Fr.I.FrimShandLunServServices
0(2013-11-14 10:41:01)日志调用筛选器:org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter
0(2013-11-14 10:41:01)日志调用筛选器:com.day.cq.wcm.mobile.core.impl.redirect.RedirectFilter
0(2013-11-14 10:41:01)日志重定向筛选器未重定向(MobileUtil.isMobileResource()返回false)
0(2013-11-14 10:41:01)日志调用筛选器:com.day.cq.wcm.core.impl.warp.TimeWarpFilter
0(2013-11-14 10:41:01)日志调用筛选器:com.day.cq.wcm.core.impl.AuthoringUIModeServiceImpl
0(2013-11-14 10:41:01)应用组件过滤器的日志
0(2013-11-14 10:41:01)日志调用筛选器:com.day.cq.personalization.impl.TargetComponentFilter
日志调用筛选器:com.day.cq.wcm.core.impl.wcmcomcomponentfilter
0(2013-11-14 10:41:01)日志调用筛选器:com.day.cq.wcm.core.impl.WCMDebugFilter
0(2013-11-14 10:41:01)计时器开始{/libs/foundation/components/primary/cq/Page/Page.jsp}
0
<html>
<% System.out.println("hello"); %>
</html>
public class YourJsp extends JspServlet {
public void jspService(HttpServletRequest request, HttpServletResponse response) {
JspWriter out = createJspWriter(response);
out.println("<html>");
System.out.println("hello");
out.println("</html>");
}
}
public void jspService(HttpServletRequest request, HttpServletResponse response) {
...
int doNothing() {
return 1;
}
}
<%!
int doNothing() {
return 1;
}
%>
<%!
public int doNothing() {
return 1;
}
%>
<%
int test = doNothing();
%>