配置form.xml,在</services:form>之前插入
<services:group?name="login"?extends="csrfCheck">
????????<services:field?name="loginError">?
????????????????<custom-error?id="invalidUserOrPassword">?
????????????????????<message>用户名或密码不正确,请重新输入</message>?
????????????????</custom-error>?
????????????</services:field>?
????????????<services:field?name="name"?displayName="账号">
????????????????<required-validator>
????????????????????<message>必须填写?${displayName}</message>
????????????????</required-validator>
????????????</services:field>
????????????<services:field?name="passwd"?displayName="密码">
????????????????<required-validator>
????????????????????<message>必须填写?${displayName}</message>
????????????????</required-validator>
????????????</services:field>
????????</services:group>
在app2/templages/screen下创建login.vm?:
$page.setTitle("login")
?
<form?action="$app2Link.setTarget("login")"?method="post">
????$csrfToken.hiddenField
????<input?type="hidden"?name="action"?value="login_action"/>
????#set?($group?=?$form.login.defaultInstance)
?
????<p>Hello,?what's?your?name?</p>
????
????#if?(!$group.csrfToken.valid)
<p>$group.csrfToken.message</p>
????#end
????
????#if?(!$group.name.valid)
????????<p>$group.name.message</p>
????#end
????
????#if?(!$group.passwd.valid)
????????<p>$group.passwd.message</p>
????#end
?
????<p>
?????????????????????账号<input?type="text"?name="$group.name.key"?value="$!group.name.value"?/><br?/>
?密码<input?type="password"?name="$group.passwd.key"?value="$!group.passwd.value"?/><br?/>
????????<input?type="submit"?name="event_submit_do_login"?/>
????</p>
?
</form>
在app2.module.screen下创建Login.java:
package?com.yunos.cloudmarket.webdemo2.app2.module.screen;
public?class?Login?{
public?void?execute()?{
????}
}
创建app2.module.action?(注意这里的app2前面应该还有你的前缀,以后不在详细说明)
在app2.module.action?下创建LoginAction.java
ok登陆页面生成了!
访问:http://localhost:8080/app2/login.htm
主要代码解析:
1.?<input?type="hidden"?name="action"?value="login_action"/& gt;这个不能少,这表示提交之后执行的是LoginAction.java,这里的value值login_action在程序内部会被处理成 LoginAction
因此这里如果写成?value="LoginAction",?结果是一样的
2.<input?type="submit"?name="event_submit_do_login"?/>这里提交后表示执行的方法是doLogin方法,如果你要执行其他方法请修改name值name="event_submit_你的方法"