首页
会员中心
到顶部
到尾部
文科毕业论文

Design and Application of Java Web Software Architecture Based on the SH Middleware

时间:2020/10/14 14:31:34  作者:  来源:  查看:0  评论:0
内容摘要: Design and Application of Java Web Software Architecture Based on the SH MiddlewareⅠ. INTRODUCTIONJava technology is currently a popular...
Design and Application of Java Web Software Architecture Based on the SH Middleware
Ⅰ. INTRODUCTION
Java technology is currently a popular language for Web development. Java Web development model has been widely used in developing B/S software application. The development of Java Web technology is attributed to the development of Internet and Browsers.
There is a significant improvement in B/S structure based software in comparison with C/S structure based software. The client code and the server code of C/S structure based software must be stored in the client and the server, respectively. The client requests to the server, the server responses and then returns the result. It brings a lot of inconvenience for the application and the maintenance because each client must install the client code.
The client of B/S structure based software is Browser. The client code and the server code are stored in Web containers (Web server). The user sends a request to the server by the client Browser, the client code is downloaded to the client computer and runs in the Browser. It no longer requires the client computer to install the client code, which is different from C/S structure based software. Thus, not only the working capacity of system maintenance on the client computer is significantly simplified, but also the operation for the user is simple and consistent.
B/S structure based software on Java Web has been constantly improved. Model1 (JSP+JavaBean) and Model2 (JSP+JavaBean+Servlet) have been developed sequentially. The latter realized the MVC model (Model+View+Controller). The trend of B/S based software development becomes more and more hierarchical in structures.                                                                            The objective of hierarchy is to separate the data from the program, separate the business logic from the display logic and separate the database management from the business logic. The hierarchical structure is good to the system expansion, so that the impact on the whole system caused by certain layer change  can be minimized.
Presentation layer: provides user certain operation interfaces, receives the client requests, and displays the response results. It also recognizes small of amount of business logic.
Business layer: recognizes the main business logic. The business code is independent, so that there is no need to know how and where to display. In addition, it is also independent to the backend database.
Data layer: is an independent backend data resource. The data can be used by different programs. Currently, the typical data resource is the relation database.
The hierarchical Web software application has rapidly become the main stream of the Web application due to the above advantages.
Ⅱ. SH TECHNOLOGY
The author has studied the architecture and design technology of Java Web software application based on SH middleware, and applied them in developing a project.
A. Struts
Struts2 is an open resource of presentation layer middleware in Java development platform. It recognizes the MVC pattern of presentation layer and it separates the view and control at presentation layer successfully. Struts2 consists of three parts: the core controller Filter Dispatcher, the logic controller Action and the view components.                                            Filter Dispatcher is a Filter running in the Web application. It is responsible for intercepting all client requests, then determines which Action handles the client request through reading a configuration file “struts.xml”.
Action obtains the information, such as client request parameters and performs business processing. It also transfers the processed results to the client display components, such as JSP, FreeMarker, Velocity, and so on .
B. Hibernate
Hibernate3 is an open resource of data layer middleware in Java development platform and a mapping tool for object/relation database. It maps the entity object to a relation database very well, shields the relation database from application software, encapsulates the relation database access into the object access, and provides an unified data access interface for upper layers.
Hibernate3 not only provides the bidirectional mapping from Java class to data table, but also supplies the mechanism for data query, data alter, data repair and data recovery. Hibernate3 can be used in J2EE and J2SE application softwares in JDBC. Hibernate3 provides HQL (HibernateQuery Language), which can be used to fully access the date resources in object-oriented way.
Ⅲ. THE SOFTWARE ARCHITECTURE BASED ON SH
The authors introduced SH (Struts2+Hibernate3) middleware during the development of their project “The Design of the System for Zhanjiang Meteorological Forecast(0910262)”. Struts2 is introduced into presentation layer and Hibernate3 into data layer.
JSP: It is the client page, using Struts2 tags and receiving  the client data from POJO in the form.
Action: It is the Struts2 Action Class, its private attributes are consistent with POJO of JSP form. Action does not need to perform large amount of business process. The major amount of business process is accomplished by business layer. Action class calls the business interface methods at business layer.
Business interface: It is a facade of business layer, which defines all business methods in a module. Each module of application software should have this interface to isolate the presentation layer from the business layer. The presentation layer and the business layer are coupled through the interface, so that it can reduce the interaction between the layers and is preferred by software expansion.
Business implement: It is the implement class for business interface, implementing all kinds of business functions of the software。
DAO interface: It is the data access interface which defines all data access methods in a module. Each module of the application software should have this interface to isolate the data layer from the business layer. The business layer and the data layer are coupled through the interface. It can reduce the interaction between the layers and is preferred by software modification.
DAO implement: It is the implement class for DAO interface, which calls the methods of the Manage Hibernate class to create Hibernate Session Factory object and to achieve the CRUD (Create, Retrieve, Update, Delete) for data access.
Manage Hibernate: It is a tool class for the Hibernate management. It contacts Hibernate directly. It provides methods to initialize Hibernate and creates Hibernate SessionFactory object according to the file “hibernate.cfg.xml” and ORM mapping files. It also provides methods to create Hibernate Session object, open Session, close Session and so on. Meanwhile, in order to recover data easily, log mechanism for the data layer should be provided and can be achieved by using Hibernate3 Log4J.
Hibernate3: It is Hibernate3 framework which is used to encapsulate the database. Each Session Factory object corresponds to a database and each Session object corresponds to a database access session. The Hibernate Session objects provide all kinds of methods for database access.
Database: It is a relation database. The MySQL 5.0 that is used by author is an open resource relation database.
Ⅳ. SOME TECHNOLOGICAL PROBLEMS IN DESIGNING
For security, each request from JSP must be acted as a Action request which is received by Struts2 Filter Dispatcher in order to avoid hyperlink between pages.
Hibernate Session Factory object is used to connect database and to create connection pool. Therefore, it consumes more system resources. It is a heavyweight and thread secure object. It should be shared by multiple threads. In order to save memory and to improve operation efficiency, static way should be adopted to use this heavyweight object.
Hibernate Session object is corresponding to a data access session. It is a lightweight object. It should be created and destroyed frequently in application software.
In order to ensure the integrity of the data, the operations collection of database access must be executed completely, so that Hibernate JTA (Java Transaction API) must be used to realize the session transaction.
Session is an insecure thread. To prevent conflicts, it is best for each thread to create one Session object in application software, i.e. each session request should have its own Session object instance. A better way is to use the Thread Local class to bind its corresponding Session object respectively.
The key code of binding Session objects:
private static ThreadLocal<Session> threLocal = new
ThreLocal<Session>();
public static Session currentSession()
{
Session cSession = (Session)threLocal.get();
if(cSession == null)
{
cSession = sessionFactory.openSession();
threLocal.set(cSession);
}
return (Session) threLocal.get();
}
public static void closeSession()
{
Session cSession = (Session)threLocal.get();
if (cSession != null)
{
cSession.close();
threLocal.set(null);
}
}
Ⅴ. S CONCLUSIONS
In this software architecture, the presentation layer uses Struts2 middleware. It receives client data, transfers the client requests to the related business module. Meanwhile, it demonstrates the responding page.
The data layer maps object/relation in the relation database by using Hibernate3 middleware. Static way should be adopted to use the heavyweight Hibernate SessionFactory object for saving the system resources, ThreadLocal class should be used to bind the lightweight Hibernate Session object to ensure the security of the thread.
Coupling through the interfaces of different layers can minimize the interaction the layers. It helps to change and expand the application software.
In order to use and manage Hibernate consistently, it is necessary to design a ManageHibernate class, which provides services for DAO.
From the front stage JSP to the back stage Hibernate, POJO is always used as transfer parameter between layers and operated as data object.
POJO of presentation layer encapsulating client data can be the same class as POJO of data layer making ORM mapping.
  


相关评论
广告联系QQ:45157718 点击这里给我发消息 电话:13516821613 杭州余杭东港路118号雷恩国际科技创新园  网站技术支持:黄菊华互联网工作室 浙ICP备06056032号