Question

I am new to grails and I am trying to access index page. After deleting the default homepage for grails, I getting the following error 404 App1/WEB-INF/grails-app/views/index.jsp

description The requested resource is not available. 

I checked UrlMapping and view is set to index

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

My controller class

package  App1grailsapp

class TeamController {

 def index() { }

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


}

And I have two gsp pages,

index

<!--
  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>

and teams

<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>

I don't understand why index.gsp page is not being shown?

Was it helpful?

Solution

View resolution for Grails is based on convention. Each controller has a directory under grails-app/views for their associated views. Unless you specify otherwise (via render) the view displayed will match the controller action name.

In your case you need to move your index.gsp to grails-app/views/ and rename your teams.gsp to index.gsp under grails-app/views/team.

Hope this helps. You may want to take a look at the documentation for further information and insight.

Also, you will need to specify what controller is used by the link to show all teams.

<li><g:link controller="team" action="index">Display all teams</g:link></li>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top