(转贴)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

 

本研究聚焦于运用Matlab对存储于.log格式中的GPS数据进行处理,此类数据通常遵循NMEA协议。NMEA是国际通用的定位数据标准,用于传输位置、速度和时间等信息。Matlab作为一款功能强大的计算与图形处理软件,为这类数据的分析与呈现提供了良好支持。 NMEA数据以$符号开头,包含多个字段,如GPGGA、GPGLL和GPRMC等,每类语句承载特定类型的GPS信息。例如,GPGGA提供定位时间与坐标信息,GPRMC则包含基本定位参数。在Matlab中,可通过`fileread`或`textscan`函数实现文件内容的读取,其中`fileread`适用于一次性读取,而`textscan`可按设定格式逐行处理,更适合复杂数据的解析。 为提取关键数据,可借助正则表达式识别语句结构,并提取如经纬度、时间、速度和方向等参数。可视化部分通常包括时间序列分析、位置轨迹绘制、速度统计以及停留时间判断等。例如,利用`geoplot`或`scatter`函数生成轨迹图,结合`geobasemap`或`geoshow`添加地图背景,以增强地理信息的呈现效果。颜色和线条样式可用于区分不同速度区间或时间段。 在开发过程中,代码的结构清晰度与可扩展性需重点关注。良好的注释和模块化设计有助于提升代码的可读性与可维护性。同时,将重复性操作封装为独立函数,如数据解析、统计计算等功能模块,能有效提升开发效率。 相关实现代码可能存在于名为“Matlab-NMEA-File-Reader-master”的压缩文件中,通过研究其结构与逻辑,有助于深入理解Matlab在GPS数据处理中的应用方式,并为类似项目提供参考。 综上所述,Matlab在处理NMEA格式GPS数据方面具有显著优势,能够实现多维度的数据分析与图形展示,涵盖数据读取、解析、统计及地理可视化等多个环节,是GIS领域的重要实践工具。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值