SSH-走通一条线之页面是怎样显示出来的?

SSH框架中,代码是怎样运行的?一条线是怎么走通的?页面是怎么显示出来的?

 

以注册为例:

点击首页点击注册

1.在首页jsp中:

<li id="headerRegister" class="headerRegister"
				style="display: list-item;"><a href="${ pageContext.request.contextPath }/user_registPage.action">注册</a>|
</li>

我们找到路径/user_registPage.action

 

2.代码跳到struts,

<!-- 配置用户模块的Action -->
		<action name="user_*" class="userAction" method="{1}">
			<result name="registPage">/WEB-INF/jsp/regist.jsp</result>
</action>

registPage就在这里,我们找到类userAction

 

3.代码跳到applicationCotnext.xml

<!-- 用户模块的Action -->
	<bean id="userAction" class="cn.itcast.shop.user.action.UserAction" scope="prototype">
		<!-- 注入Service -->
		<property name="userService" ref="userService"/>
</bean>

我们找到了包"cn.itcast.shop.user.action.UserAction"

 

4.进入到包"cn.itcast.shop.user.action.UserAction"中,找registPage方法

/**
 * 跳转到注册页面的执行方法
 */
public String registPage() {
     return "registPage";
}

5.registPage返回到struts.xml

<!-- 配置用户模块的Action -->
		<action name="user_*" class="userAction" method="{1}">
			<result name="registPage">/WEB-INF/jsp/regist.jsp</result>
</action>

struts中根据registPage跳到页面regist.jsp

 

 

我们终于跳到了注册页面,在注册页面的jsp中,循环前4步,不赘述。我们可以找到UserAction中的regist方法


	/**
	 * 用户注册的方法:
	 */
	public String regist() {
		// 判断验证码程序:
		// 从session中获得验证码的随机值:
		String checkcode1 = (String) ServletActionContext.getRequest()
				.getSession().getAttribute("checkcode");
		if(!checkcode.equalsIgnoreCase(checkcode1)){
			this.addActionError("验证码输入错误!");
			return "checkcodeFail";
		}
		userService.save(user);
		this.addActionMessage("注册成功!请去邮箱激活!");
		return "msg";
	}


之后的过程就像三层一样,往Service传数据处理,dao中连接数据库再返回值到action中,通过return "checkcodeFail""msg",转到struts中跳到不同的页面。



评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值