Macromedia Dreamweaver provides a rich visual editing environment for HTML. These functions are required in all Web development environments. Compared with other tools, Dreamweaver provides better code editing functions, including macros for Web sites, which can use certain page languages, such as ASP and ASP.. Net, JSP, ColdFusion, and PHP. The expansion macro allows you to log on automatically to implement functions similar to when to hide, automatically display result sets, and create customer result sets. You can edit and add your own code macros. There may be some code HTML or script that can be shared between different pages ). For JSP support, Dreamweaver provides a complete method/tag for JavaBeans and JSP custom tag libraries.
Dreamweaver development JSP: View
Let's start to create a view to display all the books. First, add a RecordSet for JSP in Server Behaviors, and select the table to be displayed in the table and the columns in the table:
Figure 2. Recordset dialog box
You can see that we have selected to display the Title, Authors, and Publisher fields from the Books table of the database. We will also sort the results based on the Title field. After completing this step, you can drag these fields from the Bindings window to the Web page:
Figure 3. Bindings window
Since we are creating a view, we should create a table to display the content of each row in the document:
Figure 4. Categories view
Note: This view contains several "Repeat" indicators, highlighting a row in the table, indicating that this is a Repeating Region. This is how Dreamweaver displays the RecordSet. It cyclically traverses the record and repeats the HTML content to display the RecordSet. You can also specify how many records are displayed in the Repeat Region dialog box:
Figure 5. Repeat Region dialog box
Finally, you can add a navigation bar for the result on this page. Although we can use a text or graphical navigation bar, we will use a text navigation bar for convenience:
Figure 6. navigation bar
Now we can see what the page looks like when it is displayed in a Web browser:
Figure 7. Web Page
Note: If you are on the First page, the navigation bar will hide the Prev/First section. This navigation bar also knows how to pagination based on the results. Because your repeated fields are set to show only 10 results at a time, when you click Next, this navigation bar will display the Next 10 results. When you are on the Last page, it also hides the Next/Last part of the navigation bar.
Dreamweaver development JSP: User Authentication
To support editing or classifying books in Notes, you also need to provide a separate Web UI. However, you need to create a logon page because we do not want every user to modify the category of the book. You can add several logon fields on the page to implement this function. If logon fails, an error message is displayed:
Figure 8. invalid logon page
You can create a form area to implement this function, and then add a table containing fields and field tags. The red area of the rectangle is the boundary of the form. The form operation is set to jump back to this logon page, so some code must be added to handle the actual login operation. We have added a text on the edge of the message JSP icon) to display information about users who failed to log on.
Next we will add a Login Server Behavior to this page:
Figure 9. Log In User dialog box
As you can see, you can specify the table in the database for identity authentication, and allow you to specify the access level AccessLevel field of the login user ). You can also specify the page on which the user will go after logon is successful or fails. When Logon fails, we added a query string parameter "lf ". We also added some customized code, which is the content indicated by the JSP icon) to handle this function:
- < % if (request.getParameter("lf") != null) { %>
- < p align="center">Invalid Login!< /p>
- < % } /* end request.getParameter(lf) != null */ %>
Unfortunately, this built-in Dreamweaver Server Behavior does not exist, which is different from the hidden function of the view navigation bar. For this reason, you need to use a good Java tool to implement this equivalent automatic hiding function, unless you are using a JSP custom tag library that supports this automatic hiding function.
Dreamweaver development JSP: Access Control
Dreamweaver provides a convenient way to display access to a specific page. A specific page cannot be accessed unless you have specific access permissions. Dreamweaver accesses a specific page by adding a Restrict Access Server Behavior to the page:
Figure 10. Restrict Access to Page dialog box
In this case, only users with administrator privileges can access this page. The code that actually implements this function is displayed in the visual representation of the page, and you cannot see the Code) as follows:
- < %
- // *** Restrict Access To Page: Grant or deny access to this page
- String MM_authorizedUsers="Administrator";
- String MM_authFailedURL="accessdenied.jsp";
- boolean MM_grantAccess=false;
- if (session.getValue("MM_Username") != null && !session.getValue
- ("MM_Username").equals("")) {
- if (false || (session.getValue("MM_UserAuthorization")=="") ||
- (MM_authorizedUsers.indexOf((String)session.getValue("MM_UserAuthorization"))
- >=0)) {
- MM_grantAccess = true;
- }
- }
- if (!MM_grantAccess) {
- String MM_qsChar = "?";
- if (MM_authFailedURL.indexOf("?") >= 0) MM_qsChar = "&";
- String MM_referrer = request.getRequestURI();
- if (request.getQueryString() != null) MM_referrerMM_referrer
- = MM_referrer + "?" + request.getQueryString();
- MM_authFailedURLMM_authFailedURL = MM_authFailedURL + MM_qsChar
- + "accessdenied=" + java.net.URLEncoder.encode(MM_referrer);
- response.sendRedirect(response.encodeRedirectURL(MM_authFailedURL));
- return;
- }
- %>
As you can see, it is closely bound with the Login Server Behavior.
Disadvantages of developing JSP using Dreamweaver
Dreamweaver provides a good environment for editing page language Web pages, although it cannot generate deployment descriptors ). Unfortunately, abnormal behavior violates a rule of good Web architecture: Keeping the UI and logic separated. This can be done for simple sites, but for complex and robust sites, the two must be separated. Because you need to directly add database access operations and code to JSP, this makes it more difficult to manage the Web site, unless you strictly use the Dreamweaver development environment or write your own operations. Even if you continue to use the Dreamweaver environment, there will be many problems, because you may update the Dreamweaver version, and the Server Behaviors may change, so it may not match the previous code, in this way, you need to directly modify the JSP code.
JSP tag
JSP custom labels and JavaBeans make it possible to separate the user interface from the business logic. JSP custom tags are like custom HTML tags for Web developers. JavaServer Page Standard Tag LibraryJSTL) is an essential part of JSP 1.3. JSTL contains labels that can be used to traverse result sets cyclically and implement the Hide-When function. It also provides the ability to process and convert tags in XML, and can reference objects similar to JavaScript. Finally, it provides SQL access to the JDBC source. However, if you try to separate the UI from the business logic, you should avoid using these labels.
For example, if logon fails, an "invalid login" message is displayed on the logon page. However, you need to know how to compile a Java if expression and the object from which to obtain the query string parameters:
- < % if (request.getParameter("lf") != null) { %>
- < p align="center">Invalid Login!< /p>
- < % } /* end request.getParameter(lf) != null */ %>
Use the JSP custom tag to re-compile this application. The Code is as follows:
- < c:if test="${!empty param.lf}">
- < p align="center">Invalid Login!< /p>
- < /c:if>
This is much simpler, and the Web page designers do not have to understand the Java syntax.
All database access should be hidden in JavaBeans to prevent the Web site UI from being restricted to the data in the database. Reducing the Coupling Degree of data can prevent changes in the database mode, which leads to huge changes in the business logic and user interface. If appropriate, the only thing that the JSP Web page designer needs to know is how to read the value of the JavaBean so that the appropriate part of the page can be displayed) and the URL to which the POST part of the page is usually a servlet ).
- JSP dynamic website development technology Overview
- Prospect of JSP-based e-commerce website development
- ResultSet problems caused by Microsoft driver in JSP website development
- Analysis on the advantages and disadvantages of JSP
- Advantages of JSP: Application Scope and Performance Comparison