在SSH框架中,代码是怎样运行的?一条线是怎么走通的?页面是怎么显示出来的?
以注册为例:
点击首页点击注册
1.在首页jsp中:
复制代码
1
2
3
4<li id="headerRegister" class="headerRegister" style="display: list-item;"><a href="${ pageContext.request.contextPath }/user_registPage.action">注册</a>| </li>
我们找到路径/user_registPage.action
2.代码跳到struts,
复制代码
1
2
3
4
5<!-- 配置用户模块的Action --> <action name="user_*" class="userAction" method="{1}"> <result name="registPage">/WEB-INF/jsp/regist.jsp</result> </action>
registPage就在这里,我们找到类userAction
3.代码跳到applicationCotnext.xml
复制代码
1
2
3
4
5
6<!-- 用户模块的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方法
复制代码
1
2
3
4
5
6
7/** * 跳转到注册页面的执行方法 */ public String registPage() { return "registPage"; }
5.registPage返回到struts.xml
复制代码
1
2
3
4
5<!-- 配置用户模块的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方法
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17/** * 用户注册的方法: */ 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中跳到不同的页面。
最后
以上就是寒冷仙人掌最近收集整理的关于SSH-走通一条线之页面是怎样显示出来的?的全部内容,更多相关SSH-走通一条线之页面是怎样显示出来内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复