(转贴)Struts best practices 2

本文围绕基于浏览器的n层应用展开,探讨了错误分类、服务请求者验证和应用安全问题。在错误处理上,Struts可维护错误消息栈;认证方面,介绍了不同认证检查位置;安全层面,涉及屏幕、功能、行和字段级安全,给出了Struts在各方面的最佳实践。
Page 2 of 4

Error categorization
Problem
Error handling becomes complex for an n-tiered application. In a browser-based application, the errors can be handled in the client layer using JavaScript and in the Web tier or EJB (Enterprise JavaBeans) tier using custom Java methods. Building an infrastructure for consistent error reporting proves more difficult than error handling. Struts provides the ActionMessages/ActionErrorsclasses for maintaining a stack of error messages to be reported, which can be used with JSP tags like <html: error> to display these error messages to the user. The problem is reporting a different category/severity of the message in a different manner (like error, warning, or information). To do that, the following tasks are required:

  1. Register the errors under the appropriate category
  2. Identify these messages and show them consistently

Struts best practice
Struts' ActionErrors class comes in handy in resolving the first issue of stacking messages of different categories. To display the error messages of different categories, define these categories such as FATAL, ERROR, WARNING, or INFO, in an interface. Then, in the Action or form-bean class, you can use:

errors.add("fatal", new ActionError("....")); or
errors.add("error", new ActionError("....")); or
errors.add("warning", new ActionError("....")); or
errors.add("information", new ActionError("...."));
saveErrors(request,errors);

Having stacked the messages according to their category, to display them according to those categories, use the following code:

<logic:messagePresent property="error">
<html:messages property="error" id="errMsg" >
    <bean:write name="errMsg"/>
</html:messages>
</logic:messagePresent >

Or use:

<logic:messagePresent property="error">
<html:messages property="error" id="errMsg" >
    showError('<bean:write name="errMsg"/>'); // JavaScript Function
</html:messages>
</logic:messagePresent >

Validation of service requester: Login-check
Problem
Authentication in a Web-based application can be done in any class, depending upon whether an SSO-based (single sign-on) or a JAAS-based (Java Authentication and Authorization Service) mechanism is being used. The challenge is identifying the placeholder for checking the service requester's authenticity and the user session's validity.

Struts best practice
Usual practice is to store user credentials in HttpSession after authentication. Subsequent calls check credentials' existence in session context. The question is where to place these checks. Some options are listed below, but they must be rationalized on the basis of performance overhead, possibility of future changes, and application manageability:

  • Authenticate against the session context before doing any operation (as done in Struts-example.war's CheckLoginTag.java)

  • Authenticate against session context in the Action class

  • Write servlet request filters that perform authentication

  • Extend RequestProcessor

The first two options require every JSP page or the Action class to perform the authentication against the session context. Change in the interface mandates change in all these JPS pages and classes. The third option is efficient, but overkill for the problem at hand.

The best practice is to extend the RequestProcessor class and perform authentication in methods such as processActionPerform() or processRoles().

Application security
Problem
The usual demand in Web-based applications is to have screen-level, function-level, data-row-level, and field-level security. If not suitably designed, incorporation of these security levels in an application may cause not only performance overheads, but also maintenance nightmares.

For all the security types mentioned above, the preferred approach is to place the security check in one class instead of in every component—i.e., in every JSP page or Action class.

Struts has a method processRoles() for screen- and function-level security checks, however nothing is provisioned for field- and column-level security types, making it the most challenging for most Struts users.

Struts best practice
Irrespective of where the security realm is set up (database or directory service), the best practices for the various security levels are described below:

  • For screen- and function-level security, extend RequestProcessor and override the method processRoles() to perform the check against a HashMap that stores a mapping of roles and screen IDs/function IDs

  • Row-level security is best implemented in the application's object relational mappings

  • For field-level security, tag libraries are extended to perform the check against the field ID

 

下载方式:https://pan.quark.cn/s/b4d8292ba69a 在构建食品品牌的市场整合营销推广方案时,我们必须首先深入探究品牌的由来、顾客的感知以及市场环境。 此案例聚焦于一款名为“某饼干产品”的食品,该产品自1998年进入河南市场以来,经历了销售业绩的波动。 1999至2000年期间,其销售额取得了明显的上升,然而到了2001年则出现了下滑。 在先前的宣传活动中,品牌主要借助大型互动活动如ROAD SHOW来吸引顾客,但收效甚微,这揭示了宣传信息与顾客实际认同感之间的偏差。 通过市场环境剖析,我们了解到消费者对“3+2”苏打夹心饼干的印象是美味、时尚且充满活力,但同时亦存在口感腻、价位偏高、饼身坚硬等负面评价。 实际上,该产品可以塑造为兼具美味、深度与创新性的休闲食品,适宜在多种情境下分享。 这暗示着品牌需更精确地传递产品特性,同时消解消费者的顾虑。 在策略制定上,我们可考虑将新产品与原有的3+2苏打夹心进行协同推广。 这种策略的长处在于能够借助既有产品的声誉和市场占有率,同时通过新产品的加入,刷新品牌形象,吸引更多元化的消费群体。 然而,这也可能引发一些难题,例如如何合理分配新旧产品间的资源,以及如何保障新产品的独特性和吸引力不被既有产品所掩盖。 为了提升推广成效,品牌可以实施以下举措:1. **定位修正**:基于消费者反馈,重新确立产品定位,突出其美味、创新与共享的特性,减少消费者感知的缺陷。 2. **创新宣传**:宣传信息应与消费者的实际体验相契合,运用更具魅力的创意手段,例如叙事式营销,让消费者体会到产品带来的愉悦和情感共鸣。 3. **渠道选择**:在目标消费者常去的场所开展活动,例如商业中心、影院或在线平台,以提高知名度和参与度。 4. **媒体联...
### 回答1: CMake是一个跨平台的生成代码工具,用于管理项目构建过程,它可以自动化编译过程中的各种任务,如编译、链接和打包等。在使用CMake时,有一些最佳实践需要遵循,以确保项目构建的正确性和高校。CMake Best Practices PDF是一份指南,旨在帮助用户了解如何使用CMake,并通过最佳实践来管理和构建项目。 该指南的主要内容包括使用现代CMake方法编写清晰、可读和可维护的CMake脚本,按功能分割项目并将其组织成库、模块和应用程序,并基于目标架构编写通用CMake文件,以确保跨平台的兼容性。此外,该指南还提供了一些实用技巧和工具,如依赖管理、安装和打包,以帮助开发人员进行更好的构建管理和项目发布。 总的来说,CMake Best Practices PDF是一份非常有价值的指南,旨在帮助开发人员遵循最佳实践来编写和管理CMake项目,以提高项目构建的高校和可维护性。 ### 回答2: 《CMake最佳实践(CMake Best Practices)》是一份技术文档,主要介绍了使用CMake构建C++项目的最佳实践。该文档由Daniel Pfeifer和其它CMake社区成员合作编写,为开发人员提供了一系列关于如何使用CMake构建现代C++应用程序的经验和建议。 该文档详细介绍了CMake的基本工作原理,并提供了使用CMake构建项目的步骤。同时,该文档还着重强调了在编写CMakeLists.txt文件时应该注意的细节,并提供了一些令人信服的理由。 例如,该文档建议编写简洁、模块化的CMakeLists.txt文件,避免使用过多的IF语句和过多的变量。此外,该文档也强调了对目标平台进行适当的测试、生成合适的安装脚本以及使用包管理器等最佳实践。 通过该文档的指导,开发人员可以更好地理解CMake的使用,确保其具有良好的可移植性、可扩展性和可维护性。该文档是CMake社区的重要资源之一,为C++开发人员提供了优秀的参考资料。 ### 回答3: CMake是一款功能强大的构建工具,可用于生成跨平台的软件代码。为了确保项目的顺利构建和维护,需要遵循一些最佳实践。这些实践包括: 1. 确保每个项目都有自己的CMakeLists.txt文件,以便更好地组织项目的结构和依赖关系。同时,应根据需要使用外部项目和库。 2. 编写可移植的CMake代码。这可以帮助确保代码在不同的平台上能够正确地构建和运行。 3. 使用版本控制工具管理代码,并确保将CMake配置文件包含在版本控制系统中。这可以确保在不同的开发环境之间保持一致。 4. 将构建和安装相关的命令分离到不同的CMake文件中,以便更好地管理项目。可以使用类似于“build.sh”或“install.sh”的脚本来组织这些文件。 5. 使用CMake变量来拆分项目配置,以便更好地管理和维护代码。 6. 如果有必要,可以使用预处理器语句来动态配置CMake文件。这可以帮助实现更高级的构建过程。 7. 编写清晰、易于理解的CMake文件。必要时可以添加注释或文档,以便其他开发人员能够理解和维护代码。 总之,CMake是一款非常有用的构建工具,可以帮助简化复杂的项目结构和依赖关系。但是,为了确保项目的顺利构建和维护,需要遵循一些最佳实践,并编写清晰、易于理解的CMake文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值