韩顺平struts笔记

上传人:大米 文档编号:564453459 上传时间:2024-03-09 格式:DOCX 页数:15 大小:26.30KB
返回 下载 相关 举报
韩顺平struts笔记_第1页
第1页 / 共15页
韩顺平struts笔记_第2页
第2页 / 共15页
韩顺平struts笔记_第3页
第3页 / 共15页
韩顺平struts笔记_第4页
第4页 / 共15页
韩顺平struts笔记_第5页
第5页 / 共15页
点击查看更多>>
资源描述

《韩顺平struts笔记》由会员分享,可在线阅读,更多相关《韩顺平struts笔记(15页珍藏版)》请在金锄头文库上搜索。

1、Struts视频笔记:Struts是一个开源的web框架,框架提高了程序的规范的同时也约束了程 序员的自由为什么会有struts:因为我们对mvc理解的不同,可能造成不同公司写程序 的时候,规范不统一,这样不利于程序的维护和扩展,所以我们有必要用一 个统一的规范来开发项目(struts)Struts 的好处: 程序更加规范化,开发效率提高了,可读性增加了,程序的 可维护性增加了运行原理:一个请求从浏览器发送给web服务器,http:/localhost:8080/web应用 /action,web服务器首先解析主机T然后解析web应用的名称T在解析出 资源名-转发给总司令ActionServl

2、et(该类由struts框架提供给我们的无 需编写,只需配置)TActionServlet有一个文件struts-config.xml,该文件配 置了表单actionForm(军火库),还配置了 action,以及他们之间的对应关系, 当ActionServlet拿到命令后它会查询struts-config.xml文件去填充数据,把 用户的数据填充到表单里边下个动作就是去调用指定的action(小队 长faction去从表单中读取数据,T调用某个model( 士兵,如service)完成任 务,9完成任务把结果返回给ActionServlet总司令(返回一个执行的结 果),-总司令又去查询st

3、ruts-config.xmI文件,决定跳转到哪个jsp页面,9 返回一个执行结果(形成静态html文件)9直接返回给web服务器9服务 器再把静态页面以http响应给浏览器,登录小项目过程步骤:新建web工程9导入struts包9编写Iogin.jsp9 编写actionForm和action9酉己置struts-config.xml9编写ok.jsp和err.jsp 9 配置web.xml 9测试Struts.config.xml 中的 action 中的 scope 指的是 actionform 的生命周期范 围 struts中action的scope默认是session配置过滤器pub

4、lic class MyFilter extends HttpServlet implements Filter Overridepublic void doFilter(ServletRequest arg0, ServletResponse arg1,FilterChain arg2) throws IOException, ServletException arg0.setCharacterEncoding(gb2312);arg1.setCharacterEncoding(gb2312); arg2.doFilter(arg0, arg1);酉己置web .xmlMyFiltercom

5、.chao98.services.MyFilterMyFilter/*上面这次比较浪费资源每次都要去实例化 但是下面这种过滤器不太彻底,往数据库里插入数据时还是会经常出现乱码public class MyFilter extends HttpServlet implements Filter private String encoding;public void doFilter(ServletRequest arg0, ServletResponsearg1,FilterChain arg2) throws IOException, ServletException / arg0.setCh

6、aracterEncoding(gb2312);/arg1.setCharacterEncoding(gb2312); arg0.setCharacterEncoding(encoding);arg2.doFilter(arg0, arg1);public void init(FilterConfig arg0) throws ServletException encoding=arg0.getInitParameter(encoding);然后在web.xml中加入encoding GB2312酉己置 struts-config.xml action org.apache.struts.ac

7、tion.ActionServlet config /WEB-INF/struts-config.xml debug 2detail 2 2 action *.action 写一个关于安全性的过滤器,用于过滤一些用户注册使用的关键字 private String keywords;publivcoid doFilter(ServletRequest arg0, ServletResponse arg1,FilterChain arg2) throws IOException, ServletException String username=arg0.getParameter(username

8、);System.out.println(this is safe filter !);System.out.println(username); if(username!=null)for(String key:keywords)if(key.equals(username) arg0.setAttribute(err,username+被第二个管理安全的过滤器拦截了);arg0.getRequestDispatcher(/WEB-INF/tishi.jsp).forward(arg0, arg1);return ;arg2.doFilter(arg0, arg1);public void

9、init(FilterConfig arg0) throws ServletException keywords=arg0.getInitParameter(keywords).split(; );然后在web xml配置过滤器还有设置要过滤的关键字 init-paramkeywordsxiaomao;xiaoxiao每个action是单态的,包括actionserver,对网站并发性有影响若要 证明的话在*ac tion.java中声明一个静态变量,每次访问自加 什么是单态:单态是指在整个运行过程中,始终是一个对象; struts-config.xml默认放在WEB-INF目录下,也可以放到

10、其他地方,只 需要在web.xm l中的 config/WEB-INF/struts-configxml有多个st ru ts-config.xm l只需用,“号隔开java 中 插 入 数 据 库 的 语 句 需 要 注 意 标 点 st.executeUpdate(insert into user(username,password) values(+u.getUsername()+,+u.getPassw ord()+);jst l(jsp st ar tand tag liblary) jsp标准标签库:可以提高开发速度, 代码简洁升级jsp 页面 替换8.5myeclipse:D:P

11、rogramFilesMyeclipseCommonpluginscom.genuitec.eclips e.wizards_8.5.0.me201003052220.jartempla tesjspjsp.v tl的6.5myeclipse:D:ProgramFilesMyEclipse6.5myeclipseeclipsep luginscom.genuitec.eclipse.wizards_6.5.0.zmyeclipse650200806 templatesjsp这样比较符合现在的开发潮流 各个js tl标签c:out:c:out value二hello world/c:out等同于reques t.ge tAtt rib ut e(user ).toSt ring();escapeXml表示是

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 学术论文 > 其它学术论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号