Can you tell me why I would get an HTTP Status 404 resource not available error when adding a new action to my controller in the following trivial way:
- First, I added a statement, println "in list action", to the list action which Grails generated, to make sure I'm seeing the file updates made to the contr开发者_如何学Pythonoller. This println then comes out on the console.
- I added a new action "abc" in the controller, directly copying its code from the index action, i.e. making it simply redirect to the list action.
When I enter the browser address: http://localhost:8080/myApp/user/abc it returns resource not available. Re-starting grails did not help. If I enter http://localhost:8080/myApp/user/index, it works as expected.
Thanks
I just tested it using Grails 1.3.7. You can safely end a controller action with redirect(action: "index")
, and it won't throw an error.
I'm guessing you did this:
def index = { [foo: "bar"] }
def abc = { [foo: "bar"] }
In that case, you'd need a dedicated view for both index
and abc
.
If you instead do this:
def abc = { redirect(action: "index") }
You'll get redirected correctly.
Did you create a view to go along with your action? Normally you would have a grails-app/views/user/abc.gsp
If you don't have a view you will get a 404 error since your controler will try and direct your browser to a page that does not exist.
Lesson Learned: If you get this behavior, make sure you don't have incorrect code syntax in another action.
I resolved this strange situation (to an extent anyway!). It turns out I was missing a closing brace in my top/first action, but had an extra closing brace in my second action. Don't know how this could have compiled, but apparently it did, as when I added sample new test actions further down, they worked eventually (which seemed strange). When I fixed the parenthesis issue, the second action worked then also
Note, I am doing current Grails examples without using a full blown IDE, so perhaps the IDE would have caught this error.
Had that same error, and fixed it by forcing my project to recompile completely. That means, I deleted the content of my out
directory with all the .class
files. Re-running the project then re-built all files and the intended controller action was available.
精彩评论