如何防止Grails呈现默认视图? [英] How to prevent Grails from rendering the default view?
问题描述
我正在使用Grails 1.2.1。我在我的控制器中有这个方法...
$ b $ pre $ class SocialMediaCacheProxyController {
def index = {
def url = params.url
if(params.dumpAll!= null){
transportCacheService.processCacheDump(request.getRemoteAddr(),response)
} else if(url!= null) {
doCacheTransport(request,response)
} // if
}
问题是,两个执行路径都将内容写入响应。然而,我认为Grails正在尝试在索引方法的末尾呈现一个页面,因为我在调用这个方法后反复得到下面的错误...
1339754 [http-8080-4] ERROR org.apache.catalina.core.ContainerBase。[Tomcat]。[localhost]。[/ socialmediaproxy]。[default] - Servlet.service()for servlet default throw例外
在org.codehaus.groovy.grails.web.sitemesh.GrailsPageResponseWrapper中调用response.getOutputStream()后调用response.getWriter()GrailsBuffer.getWriter(GrailsPageResponseWrapper.java: 284)
at org.codehaus.groovy.grails.web.sitemesh.GrailsPageResponseWrapper $ 3.activateDestination(GrailsPageResponseWrapper.java:125)
如何让我的方法完成后让Grails停止渲染任何想法?谢谢, - Dave
如果您不告诉Grails呈现什么,它将基于约定呈现。在你的情况下,它正在寻找一个index.gsp。控制器必须返回一些内容。这就是整个问题。所以你可以使用约定并创建一个返回的index.gsp,或者你可以手动实现render()方法。
I'm using Grails 1.2.1. I have this method in my controller … Problem is, both execution paths write content to the response. However, I think Grails is trying to render a page at the end of the index method, because I repeatedly get the below error after invoking this method … Any ideas how I can get Grails to stop rendering anything after my method is complete? Thanks, - Dave If you don't tell Grails what to render, it will render based on convention. In your case, it is looking for an index.gsp. Controllers must return something. That's the whole point. So you can either use the convention and create an index.gsp that gets returned, or you can manually implement the render() method. http://grails.org/doc/latest/ref/Controllers/render.html 这篇关于如何防止Grails呈现默认视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!class SocialMediaCacheProxyController {
def index = {
def url = params.url
if (params.dumpAll != null) {
transportCacheService.processCacheDump(request.getRemoteAddr(), response)
} else if (url != null) {
doCacheTransport(request, response)
} // if
}
1339754 [http-8080-4] ERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/socialmediaproxy].[default] - Servlet.service() for servlet default threw exception
java.lang.IllegalStateException: response.getWriter() called after response.getOutputStream()
at org.codehaus.groovy.grails.web.sitemesh.GrailsPageResponseWrapper$GrailsBuffer.getWriter(GrailsPageResponseWrapper.java:284)
at org.codehaus.groovy.grails.web.sitemesh.GrailsPageResponseWrapper$3.activateDestination(GrailsPageResponseWrapper.java:125)