[转载]来自smallfox的J2EE学习笔记系列

J2EE学习笔记(1) 开篇
http://blog.csdn.net/smallfox/

欢迎大家和我通过email讨论问题 ycmloveyou@yahoo.com 有好的建议或者对我的笔记有任何质疑也请直接了当地指出。谢谢--最基本的常识-- Cookie将对话数据存于客户端,在每个请求时发送. Session将对话数据存于服务器端,仅将sessionid存于cookie,这种方法有更好的安全保障,对服务器要求也更高. 基于这一点,struts的默认scope是request,而非session. 程序员在页面间传输数据时也应尽量用request scope以减少服务器负担. --比较基本的一个常识--在利用Struts构建的jsp含有html,javascript,jsp scriptlet和struts tags, 执行时的顺序为 jsp scriptlet -> tag library -> html+js. 所以html和js代码可以嵌套 等代码,在struts tag里也可以嵌套scriptlet代码,但反过来就是错的. 实际应用中常用 在html以comment方式显示bean property内容来debug,就是一个典型的例子--最重要的软件工程实践--应用了struts的jsp里绝对不能再掺杂处理商业逻辑(Strongly discouraged),scriptlet只适用于完全用于presentation的逻辑处理,而商业逻辑应放到action/ejb/dao层处理. 写在jsp里哪怕一点点的business logic都会让日后的维护付出高昂的代价。

J2EE学习笔记(2) Javascript 讨论

其实Javascript不属于严格的J2EE范畴,但由于它的轻量级和快速强大的客户端功能,使得我们不得不对Javascript礼让三分. 下面是我很有限的一些javascript经验 1) javascript主要用来捕捉客户端事件,数据表格的校验,控制页面的跳转导向. 每一项都有足够多的内涵可以挖掘,这里就不多说了 2) 就校验而言, 一般说服务器端还是要做再一次的检验以保证数据的一致与有效(防止客户端故意关闭javascript检查) 3) Javascript非常强大,但不是万能的,比如说,很多情况下是不能利用JS回到上一页面的(history.back()),原因主要是防止重复提交表单,一般这种情况用Action导向到当前页面的初始化Action Method (典型的例子为 XXXAction.do?method=initYYY

J2EE学习笔记(3) Struts Logic Tags

Logic Tags

语法应用是 --
<someComparisonTag value="someUserNameValue" cookie="userName"> (cookie specifies the name of the cookie to compare with value)
<someComparisonTag value="en_US" header="Accept-Language"> (header specifies the name of the HTTP header to compare with value)
<someComparisonTag value="someUserNameValue" parameter="username"> (parameter specifies the name of the request parameter to compare with value)

<someComparisonTag name="testBean" property="propNameInTestBean" value="someValue"> (典型)
name指定了bean的名字而property指定了该bean的某个property以便于与value比较, 通常我们还可以加一个scope来限制bean
property is used in conjunction with name to specify a property in the bean specified by name. The property reference can be simple, nested, and/or indexed. For the type of syntax used for property, see the users guide on the Bean Tags.
scope specifies the bean scope which can be page, request, session, application, "any scope" (default)

1) 值比较 Value Comparison: equal, notEqual, greaterEqual, lessEqual, lessThan, greaterThan
比较逻辑是 -- 先试图convert成long double,并比较; 如果parse失败就会用String.equalTo()来比较

1) 值比较 Value Comparison: present, notPresent, empty, notEmpty
present看的是某变量/实例是否存在于某个限定范围,empty看的是该实例是否为null, "", or collection.isEmpty()==true (only for collection)

2) 子字符串匹配 Substring Matching: match, notMatch
match/notMatch 还有一个可选location来指定该substring必须出现在字符串开始还是结尾 (location="start/end")

3) Presentation Location: forward, redirect
用法尚不清楚

4) Collection Utilities: iterate (极常用)
<logic:iterate id="searchResultList" name="<%=WebKeys.SEARCH_RESULT_LIST_TWO%>" scope="session">
<bean:write name="searchResultList" property="itemName"/></a>
<bean:write name="searchResultList" property="itemUnitOfMeasure" />
<bean:write name="searchResultList" property="inventoryDetailSize" format="#0.00"/>
</logic:iterate>
如果property给定,name代表了一个bean的实例,而这个bean的getThatProperty()将返回此tag需要的collection实例,
如果没有给定property, name本身就指定了将被iterate的collection的实例,
id给出了每一次循环的collection的当前object的名字,用于在内部使用
offset和length指定了从collection的哪个位置开始,到哪里结束,其他请参见Struts Documentation,这里不详述

J2EE学习笔记(4) 软件工程与系统框架

J道的老大banq曾经说过设计模式是衡量一个程序员水平高低最重要的标准。个人非常赞同这个观点,从这个角度看学好J2EE第一个要了解的就是作为一个庞大复杂的系统,它是如何由各个模块拼装并协同有效地运作。 先来几个定义暖暖身Definitions of Different Dimensions in J2EE Tiers: A logical or physical organization of components into an ordered chain of service providers and consumers. Components within a tier typically consume the services of those in an "adjacent" provider tier and provide services to one or more "adjacent" consumer tiers. Within a tier, services are grouped to like requirements, such as functionality, security, or load distribution. Layers: The hardware and software stack that hosts services within a given tier. Physical, network, and software platforms and standard API sets support the components that provide a service. Layers, like tiers, represent a well-ordered relationship across boundaries that are mediated by interfaces. Whereas tiers represent processing chains across components, layers represent container/component relationships in implementation and deployment of services. Tiers层的概念是我们最常听到的,一般来说它可以分为 (客户) <---交互---> [ Client Interface --- Presentation Tier --- BizLogic Tier --- Integration Tier --- Resource Tier ] Client Interface 典型的客户界面为IE, Swing, Applet, WAP等,客户与之直接交互 Presentation Tier 负责接受客户请求并返回相应的处理结果。登陆,权限检查,会话管理在此进行,从技术角度就是JSP HTML等 Business Logic Tier 负责处理业务逻辑和数据,是J2EE的核心,它也同时管理事务Transaction,EJB等在这一层 Integration Tier 负责连接业务逻辑层与系统资源层,最常见的JDBC数据库连接就是一个例子 Resource Tier 负责提供上层所需要的资源,比如数据库, File System, Legacy System等等结合实际应用和设计模式,我们可以将层次进一步划分。多层次会降低效率,也会导致出现很多看似“无用”的代码,但正是这些代码实现了低耦合从而降低了后期维护成本。 1) Presentation Tier应用MVC模式, 将程序流程控制器(Controller) 视图(View)和数据三者分离,如Struts就是其中一员大将。Filtering和User-Role-Priviledge-Resource也常在使用(具体还会开新贴细谈) 2) Business Logic Tier 和Presentation Tier的低耦合由Business Delegate层实现,很典型的例子 BusinessDelegate -> BusinessMgr (EJB) -> ...而Facade模式也经常在这里被用来做封装。主要参考文献:软件体系架构模式在J2EE中的应用主要参考项目:Medlog Logistic PACE2 SCS

J2EE学习笔记(5) 角色权限资源管理的实现

文章将在近期更新发表。主要参考文献: http://www.jdon.com/jive/article.jsp?forum=46&thread=2897 http://www.jdon.com/jive/article.jsp?forum=46&thread=4110&message=438816 http://www.jdon.com/jive/article.jsp?forum=46&thread=10122

J2EE学习笔记(6) Struts HTML Tags

HTML Tags

一些公用的tag attributes在HTMLTagLib里的含义前后一致,它们是
name: ActionForm bean的实例名,如果name不存在,<html:form>所关联的formBean会生效。
property: property既决定了生成的html的fieldname,也决定了该field的值 via formBean.getThisProperty
value: value决定了生成html的field的value,注意它不是bean的propertyName

剩下的以后慢慢加。。。

消息(错误)显示

ActionMessages messages = new ActionMessages();
messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("userForm.insert", info.getUserName());
messages.add("activationDate", new ActionMessage("userForm.active", info.getDateLength());

如下可以显示所有消息,并用<li>将它们放入一个list,再加上可定制的header/footer
<html:messages id="message" header="errors.header" footer="errors.footer">
   <li><bean:write name="message"/></li>
</html:messages>

如下可以指定只显示某种message
<html:messages id="message" property="<%= org.apache.struts.action.ActionMessages.GLOBAL_MESSAGE %>">
   <li><bean:write name="message"/></li>
</html:messages>

把Messages换成Errors就是错误显示,为了简便,经常一个<html:errors/>了事


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值