14.8 Struts2 基础之 实践与练习
14.8 实践与练习
1. 实现用户的中间退出, 用户登录成功后, 当单击"安全退出"按钮时, 即可实现用户的退出. (源码位置: disc\TM\sl\14\5)
2. 通过 Struts2 框架实现日期转换器. (源码位置: disc\TM\sl\14\6)
3. 实现空表单信息的提示. (源码位置: disc\TM\sl\14\7)
14_5 的 部分源码
注意: 使用 struts-Convention-plugin, 无需配置文件 struts.xml
package cn.mrcast.action; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; import com.opensymphony.xwork2.ActionSupport; @Results({ @Result(name="success",location="/success.jsp"), @Result(name="error" ,location="/error.jsp"), @Result(name="exit" ,location="/index.jsp") }) public class LoginAction extends ActionSupport{ private String username; private String password; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Action("login") public String execute() { if(username.equals("mr")&&password.equals("mrsoft")) { return "success"; } else { return "error"; } } @Action("ex") public String exit() { return "exit"; } }
相关推荐
hgzhang 2020-05-06
白净垃圾桶 2020-05-04
playis 2020-04-18
郭大路路 2020-04-16
lenchio 2020-04-08
yixiaoqi00 2020-04-08
melonjj 2020-01-05
mmywcoco 2019-12-28
wangruiling 2014-06-13
yaoyao0 2014-06-01
YangHuiLiang 2014-05-20
方志朋 2019-12-22
xcguoyu 2014-01-18
方志朋 2015-04-30
殷龙飞 2014-06-24
zmysna 2016-12-16
89264255 2011-04-23
wuddny的blog 2014-12-04