Using JavaBean to efficiently process JSPs (4)

Source: Internet
Author: User
JS Final point: Framework

By separating performance from logic, the architecture allows you to modify performance (JSP) and logic (beans) independently. This means that you can modify the logic in the bean without changing the JSP, as long as you keep the Bean's properties unchanged. Instead, you can give your JSP code to HTML developers and artists to change the appearance of the site without affecting the Java code.

You can modify the core elements of the framework slightly to meet the special needs of your application. You can add new or modify existing methods, or modify the template method. The important point is that throughout your application, all JSP and JSP JavaBean should use this architecture.

At the outset, the architecture seemed more complex, especially for a three-page example application. However, if you start to write your application, you will find that when the application becomes more complex, the increase in code volume is not as large as expected.

This architecture does not talk about multi-tier designs that are typically used in Web applications. It mainly concentrates on the performance layer of JSP. To build a real three-tier or multi-tier system, JSP Javabeamn will need to invoke enterprise JavaBean or some other business logic implementations.

The example also describes the schema that lets applications track HTTP sessions. However, if you do not want to rely on session, the architecture can still work well. The pages and processes applied should be designed separately. You may not need to sharedsessionbean. Your page is just for performance, and stand-alone pages will be used only for processing and validation, without any HTML output. To do this, you will mainly use the Beanfirstpassprocess () method.

The final point: examples

I use Tomcat3.1 to test this example, Tomcat3.1 conform to JSP1.1 and Servlet2.2 specifications. This article will not discuss the details of how to configure JSP applications in Tomcat.

When testing This example, you can get the voter ID in the source code of the Votedb class so that you can perform a login test (the password and ID are the same).

You must allow cookies in the browser, otherwise you cannot run the example successfully. If you need to be able to run this application while prohibiting cookies, you must write the URL again (using the Encodeurl () method of the Javax.servlet.http.HttpServletResponse class). You need to rewrite the URLs in all applications, including the links in your JSP, the action in the form tag, and the HTTP request to redirect the URL in the JSP JavaBean.

Conclusion

The architecture presented in this article provides a comprehensive solution to the application design of JSP. It improves code reuse, determines the application system, and facilitates scaling. One of the biggest benefits is separating performance from logic, and you can change them independently without affecting the other side.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.