In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you in the use of JSP technology to build a dynamic website in the process of technical problems, I believe that most people do not know much, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Among the many websites of Internet, the dynamic website based on Web database is widely used. The dynamic website based on Web network database is composed of a Web browser as the client interface, a database server for information storage and a Web application server connecting the two. With the continuous development of the client technology of Web applications, the original CGI technology for developing dynamic websites has been gradually replaced by Java Applet, ActiveX controls, DHTML and JavaScript. These technologies have greatly improved the user interface, but when they try to do some in-depth work, they begin to encounter problems such as incompatibility of client browsers, heavy burden on servers, slow access speed, and security.
JSP Web development technology
JSP is a Web development technology based on Java Servlet and the whole Java system, which can be used to build advanced, secure, fast and cross-platform dynamic websites. Add Java program fragments and JSP tags to the traditional web page HTML file to form a JSP web page. When the Web server receives the request to access the JSP web page, it first executes the program fragment, and then returns the execution result to the customer in HTML format. Program fragments can manipulate the database, redirect web pages, send E-mail, and so on, which are the functions needed to build a dynamic website. All the program operations are performed on the server side, and what is transmitted to the client on the network is only the result, and the requirement for the client browser is very low. As shown in figure 1, when the user connects to the JSP website, the user requests the web page, and the JSP page responds to the request alone, transforms the user's request to the web page into a request for data, processes the request through JavaBean and encapsulates the returned data into a HTML page to return to the user.
JSP Web development has many advantages:
1. If the program is written once, it can be run everywhere. JSP is designed with full consideration of the irrelevance of the application platform. Depending on the portability of Java, JSP is supported by many popular operating platforms and can be executed on Apache, NetScape, IIS and other servers.
two。 The execution speed is fast. JSP pages only need to be compiled once into Java bytecode, and then reside in the server memory all the time, speeding up the response to JSP pages. Regardless of the time it takes for JSP pages to be compiled *, JSP responds much faster than ASP.
3. The advantages of Java. JSP technology uses Java as the scripting language. Cross-platform, mature, robust, and extensible Java technology makes the work of developers easier and easier in other ways. When the Windows system is suspected to crash, Java can effectively prevent the system from crashing. The Java language plays an important role in memory management by providing ways to prevent memory leaks. In addition, JSP provides a more robust unexpected event handling mechanism for applications, giving full play to the advantages of Java.
Technical difficulties in JSP Web development
1. Connect to the database
Database connection is the most important part for dynamic websites, and ODBC or JDBC technology can be used to connect with back-end databases. Although ODBC is an option as a traditional means of connecting to a database, ODBC has the following fatal flaws that make it incompetent for JSP requests:
(1) ODBC is an API implemented in C language. Calling local C programs from Java programs will bring a series of similar security, integrity and robustness problems.
(2) second, it is not satisfactory to implement a completely accurate ODBC translation from C code ODBC to Java API, because there are no pointers in Java, and pointers are heavily used in ODBC, including the error-prone null pointer "void *".
(3) considering the portability of the platform, the use of ODBC in JSP Web development will have a negative impact, which makes the code not suitable for migration.
In order to make the program have security, integrity, robustness and transplant conveniently, it is more appropriate to use JDBC to connect to the database. JDBC is a kind of Java API that can be used to execute SQL statements. It consists of some classes and interfaces written in Java language, which enables developers to write complete database applications in pure Java language. By using JDBC, you can easily transfer SQL statements to almost any kind of database. In other words, you don't have to write one program to access Sybase, another program to access Oracle, and another program to access Microsoft's SQL Server. The program written in JDBC can automatically transmit SQL statements to the corresponding database management system.
When the local database program uses the database such as Microsoft's Access, the JDBC-ODBC bridge developed by Sun Company can be used. By using this technology, the JSP program can access the database with ODBC driver. This not only retains the advantages of JDBC, but also connects to Access using the ODBC data source provided by Microsoft. No matter what kind of database the other party is, as long as there is an ODBC interface, you can directly use the JDBC-ODBC bridge to connect with the database without changing the corresponding program code due to the change of the back-end database, thus realizing the separation of the application layer and the database layer. If you need to change the back-end database to MySQL, you can use the MySQL database directly after installing the MySQL driver in the ODBC data source.
two。 Built-in component
In the implementation of the website, due to the objective needs, in order to easily distinguish between local LAN users and remote connected users, and to provide corresponding permissions, the built-in component Request can be used to capture the IP address of each user connected to the server, and the corresponding permissions are given after comparison. In this way, users in the local area network can use all the open and non-public resources in the website. The existing method can also be improved by entering various IP addresses into the database and giving different IP addresses different permissions to completely control users' use of website resources.
Session state maintenance is a problem that Web application developers must face. In order to know whether the user is still online, using the built-in Session component, by giving each logged-in user a Session variable, you can close the resources used by the user after the user leaves the site abnormally, so as to save memory and improve the performance of the server.
The Cookie class is also provided in JSP, whose constructor has two parameters that represent the name and value of the Cookie, respectively. The Cookie class provides various methods to set the properties of Cookie, such as setting the lifetime of Cookie through the setMaxAge method. If the survival time is negative, it means that the browser closes Cookie, that is, it disappears; if the survival time is 0, the survival time of deleted Cookie; is positive, which means how many seconds Cookie exists. Cookie can be used to temporarily save the user's account and password, and JSP can be read at any time to verify the validity of the user. The browsing status of the user can be saved in Cookie, and the next time the user visits the web page, the JSP will display the personalized page to the browser.
3. Convert Unicode coding
Problems caused by Chinese character coding and Unicode coding conversion have been encountered in the debugging of many JSP pages, such as Chinese characters in JSP pages seen in browsers are garbled, JSP pages cannot display Chinese characters properly, JSP can not receive Chinese characters submitted by forms, JSP database can not read and write correct content, and so on. This is because most of the core character processing of software with international characteristics is based on Unicode. When the software is running, the corresponding local character encoding settings are determined according to the "Locale/Lang/Codepage" setting at that time, and local characters are processed accordingly, so the conversion between Unicode and local character sets, or even two different local character sets mediated by Unicode, should be realized in the process of processing. This method is further extended in the network environment, and any character information at both ends of the network needs to be converted into acceptable content according to the setting of the character set.
Since the default character set of IE is GB2312, while Windows defaults to GBK,Java and defaults to Unicode, it will be garbled to display pages from GBK or Unicode directly on the GB2312 character set without some conversion. Java language uses Unicode to process characters, but from another point of view, non-Unicode can also be used in Java programs. it is important to ensure that the Chinese character information at the entrance and exit of the program is not distorted. If completely using ISO-8859-1 to deal with Chinese characters can also achieve correct results, after conversion and forced to set the web character set to GB2312 character set display, Chinese characters can be displayed normally.
These are all the contents of this article entitled "what are the technical problems in building a dynamic website using JSP technology?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.