深入浅出了解Struts的处理流程(有图有真相)
Struts框架在java web开发中很常用。最近我也在逐步摸索和学习。今天就来说说Struts的处理流程。
先来一幅Struts工作原理图:
从上面这幅图,我们可以清楚的看到Struts的实现原理:
客户端的每个请求,都会首先到达ActionServlet,截取url;ActionServlet会根据截取的url,在struts-config.xml的action-mapping中,找到对应action的配置信息,然后读取到ActionMapping中;
ActionServlet拿到ActionMapping中的name属性值,再从form-beans中找到对应的ActionForm,反射出实例来。将页面表单内容通过自动转换器转换后,放入到这个ActionForm中,传递给action处理类;
Action处理类拿到ActionForm,即可获取表单数据。通过ActionMapping则可以实现页面的转发。
上面就是Struts工作原理的基本流程。通过断点调试struts,详细解释一下运行的流程:
通过查看代码得知,
ActionServlet是通过process()方法来处理全部逻辑的。action配置信息并不是全部加载,而是找与截取的url对应的action配置信息,加载到ActionMapping中,也就是一个action对应一个ActionMapping。
ActionForm也并不是每次都反射,而是会先判断一下request或者session中是否已经创建,如果没有,则创建一次,并保存在request或者session中。
Action处理类同样是先检查是否已经创建过,然后在操作。而且struts1中的Action创建过程存在线程安全问题。
ActionServlet根据Action返回的ActionForward,调用processForwardConfig,进行页面导航。
- 1楼u0121195931小时前
- www.laiwu.net/blog-484450-1162899.htmln www.laiwu.net/blog-484450-1162985.htmln www.laiwu.net/blog-484450-1163218.htmln www.laiwu.net/blog-484450-1163361.htmln www.laiwu.net/blog-484450-1163426.htmln www.laiwu.net/blog-484450-1163511.htmln www.laiwu.net/blog-484450-1163576.htmln www.laiwu.net/blog-484450-1163600.htmln www.laiwu.net/blog-484515-1163779.htmln www.laiwu.net/blog-484515-1163805.htmln www.laiwu.net/blog-484515-1163822.htmln www.laiwu.net/blog-484515-1163848.htmln www.laiwu.net/blog-484515-1163869.htmln www.laiwu.net/blog-484515-1163940.htmln www.laiwu.net/blog-484515-1164029.htmln www.laiwu.net/blog-484515-1164054.htmln www.laiwu.net/blog-484515-1164090.html