js| Create This example, the view includes two components:
• One JSP file: hello.jsp
• A actionform bean:helloform Bean
How to create these two components is described below.
Create a JSP file
HELLO.JSP provides a user interface that accepts user-entered names. In addition, all output from this Web application is displayed to the user by hello.jsp. Figure 2-1 shows the Web page provided by hello.jsp.
Figure 2-1 Hello.jsp's Web page
In Figure 2-1, after the user enters the name "Weiqin", by submitting the form, the application returns "Hello weiqin!", see Figure 2-2.
Figure 2-2 hello.jsp A Web page that is normally returned after user input is accepted
Routine 2-1 is the source code for the hello.jsp file.
Routine 2-1 hello.jsp <%@ page contenttype= "Text/html;charset=utf-8" language= "java"%><%@ taglib "uri=" Struts-bean.tld "prefix=" Bean%><%@ taglib uri= "/web-inf/struts-html.tld" prefix= "html"%><%@ taglib uri= "/web-inf/struts-logic.tld" prefix= "logic"%>
The above JSP files based on the Struts framework have the following characteristics:
• No Java program code
• The use of many of the client labels for struts, such as And Label
Without directly providing textual content, instead Labels, the text content that is printed on the page is made up of tag to generate the. For example:
The Struts client label is the link between the view component and other components in the Struts framework. These tags can access or display data from the controller and model components. In this book, chapters 12th through 16 are devoted to the use of the Struts label, this section introduces briefly several important struts tags.
The first few lines of hello.jsp are used to declare and load the Struts tag library:
<%@ taglib uri= "/web-inf/struts-bean.tld" prefix= "Bean"%><%@ taglib uri= "/web-inf/struts-bean.tld" prefix= " Bean "%><%@ taglib uri="/web-inf/struts-bean.tld "prefix=" Bean%><%@ taglib uri= "/web-inf/ Struts-html.tld "prefix=" html%><%@ taglib uri= "/web-inf/struts-logic.tld" prefix= "logic"%><%@ taglib Uri= "/web-inf/struts-logic.tld" prefix= "logic"%>
The above code indicates that the JSP file uses a struts Bean, HTML, and logic tag library, which is the standard JSP syntax for loading a custom tag library.
tags from the Struts HTML tag library are used in hello.jsp, including , And :
· : Used to display error messages from other components in the Struts framework.
· : Used to create an HTML form that associates the fields of an HTML form with the properties of a actionform bean.
· : The label is A child label that is used to create a text box for an HTML form. It is associated with the properties of the Actionform bean.
Two tags from the Struts Bean tag library are used in hello.jsp And :
: Used to output localized textual content, its key attribute specifies the message key, and the text content that matches the message key comes from a dedicated resource Bundle, the concept of resource Bundle See Chapter 9th of this book (Internationalization of Struts application).
: The property value used to output JavaBean. In this case, it is used to output the value of the Username property of the Personbean object:
Hello.jsp used a logic tag library from the Struts label. The label is used to determine whether the JavaBean exists within a specific range, and only if JavaBean exists will the contents of the label body be executed:
In this case, The label is used to determine whether a Personbean object exists within the request scope and, if so, to output the Personbean Username property value. The label is relative to the label, which means that the contents of the label body are executed only if the JavaBean does not exist within a specific range.
[1] [2] next page