groovy - Grails - 404 File not found - but why? -
i start write simple login formular. code view:
<g:form controller="login" action="checkusernameandpassword"> <input type = "text"name="usernamefield" value="username"/> <input type = "password"name="passwordfield" value="password"/> <input type = "submit" name="loginbutton" value="login"/> </g:form>
this code controller:
class logincontroller { def index = { render(view: "login") }//endmethod index def checkusernameandpassword = { [username = params.username ,password = params.password]; }//endmethod checkusernameandpassword
}
as can see, doesnt yet, wanted print values on screen, 404 message (i run file on local host)
the requested resource (/projectname/hello/checkusernameandpassword) not available.
i cant figure out why. great if of guys have tip me.
beste regards, daniel
edit (change 1):
def checkusernameandpassword = { render(view: "login",model: [username: params.username ,password: params.password]) }//endmethod checkusernameandpassword
}
(change 2) //added line in view
<div>username: ${username} passwort: ${password}</div>
<g:form controller="hello" action="checkusernameandpassword">
means have hellocontroller checkusernameandpassword action
but in code sample have logincontroller form work, must write:
<g:form controller="login" action="checkusernameandpassword"> <input type = "text" name="usernamefield" value="username"/> <input type = "password" name="passwordfield" value="password"/> <input type = "submit" name="loginbutton" value="login"/> </g:form>
p.s. in grails world better use gsp tags instead of plain html because generate proper(in 99.99% of cases) html code you. best way implement form is:
<g:form controller="login" action="checkusernameandpassword"> <g:textfield name="usernamefield" value="username" /> <g:passwordfield name="passwordfield" value="password" /> <g:submitbutton name="loginbutton" value="login" /> </g:form>
p.s.2 proper logincontroller code(for form described before)
class logincontroller { def index = { render(view: "login") }//endmethod index def checkusernameandpassword = { [username: params.usernamefield ,password: params.passwordfield]; }//endmethod checkusernameandpassword
Comments
Post a Comment