【发布时间】:2016-09-29 16:12:27
【问题描述】:
我在显示 .gsp 文件时遇到一些问题,我不太确定原因。我有以下代码:
class UrlMappings{
static mappings = {
"/"(controller: 'index', action: 'index')
}
}
class IndexController{
def index(){
render(view: "index")
}
}
然后在 grails-app/views/index 我有 index.gsp:
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
Hello World
</body>
</html>
当我点击 http://localhost:8080/ 时,我收到 500 状态代码错误。但是,如果我将 IndexController 更改为具有
render "Hello World"
它将显示“Hello World”,因此应用程序似乎正在启动。
有人知道发生了什么吗?部分堆栈跟踪:
17:09:40.677 [http-nio-8080-exec-1] ERROR o.a.c.c.C.[.[.[.[grailsDispatcherServlet] - Servlet.service() for servlet [grailsDispatcherServlet] in context with path [] threw exception [Could not resolve view with name '/index/index' in servlet with name 'grailsDispatcherServlet'] with root cause
javax.servlet.ServletException: Could not resolve view with name '/index/index' in servlet with name 'grailsDispatcherServlet'
【问题讨论】:
-
看起来很奇怪。只需确保您已运行经典的
grails clean并重新启动 Grails 运行时即可。 -
避免在框架中使用具有特定含义的名称。如果将 Index 更改为其他内容,是否会出现相同的错误?
-
也不会
http://host/index/index看起来有点不对劲吗?无论如何 "/index"(controller: 'aha', action:"nice" ) 怎么样,然后将/index重定向到其他一些控制器操作,您也可以为/index/index编写它,但认为它看起来有点奇怪人们开始质疑开发人员的技能:)