无法访问grails中的index.gsp

时间:2014-02-22 20:57:12

标签: grails gsp grails-controller

我是grails的新手,我正在尝试访问索引页面。删除grails的默认主页后,我收到以下错误     404 App1 / WEB-INF / grails-app / views / index.jsp

description The requested resource is not available. 

我查看了UrlMapping,并将视图设置为索引

    "/"(view:"/index")
    "500"(view:'/error')

我的控制器类

package  App1grailsapp

class TeamController {

 def index() { }

    def teams()
    {
        [teams:Team.list()]
    }


}

我有两个gsp页面,

索引

<!--
  To change this license header, choose License Headers in Project Properties.
  To change this template file, choose Tools | Templates
  and open the template in the editor.
-->

<!DOCTYPE html>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Sample title</title>
    </head>
    <body>
      <h2><g:message code="welcome"/></h2>

        <ul>
            <li><g:link action="teams">Display all teams</g:link></li>

        </ul>
    </body>
</html>

和团队

<html>
    <head>
        <meta name="layout" content="main">
        <title>Teams</title>
    </head>
    <body>
        <h2>Teams:</h2>

        <table>
            <tr>
            <thead>
                <th>Name</th>

            </thead>
            </tr>
            <g:each var="team" in="${teams}">
                <tr>
                    <td>${team.name}</td>

                </tr>
            </g:each>
        </table>
    </body>
</html>

我不明白为什么没有显示index.gsp页面?

1 个答案:

答案 0 :(得分:1)

Grails的查看分辨率基于约定。每个控制器在grails-app / views下都有一个目录,用于关联的视图。除非您另行指定(通过渲染),否则显示的视图将与控制器操作名称匹配。

在您的情况下,您需要将index.gsp移至grails-app/views/并将teams.gsp重命名为index.gsp下的grails-app/views/team

希望这会有所帮助。您可能需要查看documentation以获取更多信息和见解。

此外,您需要指定链接使用哪个控制器来显示所有团队。

<li><g:link controller="team" action="index">Display all teams</g:link></li>
相关问题