Struts2应用程序,允许用户在在线调查表中注册
来源:互联网 发布:宏远体育工作感受 知乎 编辑:程序博客网 时间:2024/06/11 12:26
功能:
发一个Struts2应用程序,允许用户在在线调查表中注册。仅当用户已访问条款页面并接受其中的条款时才会显示注册页面。如果用户拒绝接受条款,则转向用户显示首页。如果用户单击注册页面上的“提交”按钮,则应向他显示欢迎页面。用户应该能够从欢迎页面转至首页,然后从首页访问注册页面。
package action;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.interceptor.AbstractInterceptor;public class Interceptor extends AbstractInterceptor {@Overridepublic String intercept(ActionInvocation arg0) throws Exception {// 获取action中的session方法Object object= ActionContext.getContext().getSession().get("ss");// 判断object是否为空 if(object==null){// 如果object为空 返回error 返回错误页面 return "error"; }else{// 如果object不为空 返回arg0 执行目标方法 (注册页面) return arg0.invoke(); }}}
创建ReadAction
package action;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;public class ReadAction extends ActionSupport{@Overridepublic String execute() throws Exception {//把ss存进session中ActionContext.getContext().getSession().put("ss", true);return SUCCESS;}}
创建进入注册页面的RegisterAction
package action;import com.opensymphony.xwork2.ActionSupport;public class RegisterAction extends ActionSupport {@Overridepublic String execute()throws Exception{return SUCCESS;}}配置struts.xml
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""http://struts.apache.org/dtds/struts-2.3.dtd"><struts><package name="hello" namespace="/hello" extends="struts-default"><!-- 拦截器 判断是否点击阅读 条款 --><interceptors > <interceptor name="xxx" class="action.Interceptor"> </interceptor></interceptors><action name="register" class="action.RegisterAction"><!-- 拦截器 --><interceptor-ref name="xxx"></interceptor-ref><result name="success">/enroll.jsp</result><result name="error">/terms.jsp</result></action><action name="read" class="action.ReadAction"><result name="success">/enroll.jsp</result><result name="error">/terms.jsp</result></action></package></struts>
运行效果:
0 0
- Struts2应用程序,允许用户在在线调查表中注册
- Struts2中允许用户自行选择程序语言
- Jenkins设置允许用户注册
- struts2学习笔记(三)—— 在用户注册程序中使用验证框架
- iOS中允许后台应用程序刷新在开发中的注意事项
- 使用VB在应用程序中注册热键
- 使用VB在应用程序中注册热键
- 在注册表中注册应用程序的数据文件
- 使用VB在应用程序中注册热键
- 在注册表中注册应用程序的数据文件
- 在Surface Shell中注册Surface应用程序
- 【struts2】用户注册系统
- asp.net注册用户并不允许注册已有的用户
- 实现只允许注册用户下载文件
- 在struts2.0中国际化(i18n)应用程序
- 在.net应用程序中使用用户控件
- 在.net应用程序中使用用户控件
- 在.net应用程序中使用用户控件
- 使用CHtmlView制作浏览器的简单记录
- 开方数_ny_773(大数).java
- 新导入工程报Unable to resolve target 'android-18'和R cannot be resolved
- funciton snprintf
- hdu2473 Junk-Mail Filter 设虚父结点删除节点
- Struts2应用程序,允许用户在在线调查表中注册
- Git简明教程
- POJ 3264 Balanced Lineup
- 【C++】PAT(basic level)1015. 德才论 (25)
- HDU 3033 I love sneakers! (分组背包)
- windows 8.1 安装
- 大型应用强者愈强,新的开发者正在寻找更细分的领域
- (12)获取文件信息
- 蓝桥杯-代码填空之三