Java Server Pages: A Code-Intensive Premium Reference- P16
Số trang: 10
Loại file: pdf
Dung lượng: 273.26 KB
Lượt xem: 10
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Java Server Pages: A Code-Intensive Premium Reference- P16:Before you begin reading Pure JSP Java Server Pages, you might want to take a look at its basicstructure. This should help you outline your reading plan if you choose not to read the text from cover tocover. This introduction gives you an overview of what each chapter covers.
Nội dung trích xuất từ tài liệu:
Java Server Pages: A Code-Intensive Premium Reference- P16 + (String)cfgTable.get(new String(ID)) + ); out.println(DESCRIPTION + + (String)cfgTable.get(new String(DESCRIPTION)) + ); out.println(PRICE + + (String)cfgTable.get(new String(PRICE)) + ); System.out.println(QUANTITY + + (String)cfgTable.get(new String(QUANTITY)) + );%> As you can see, there is really very little difference in the application code and the JSP code. The onlynoticeable differences are the way we load the XMLResource and the way we output the results. To seethis JSP run, you will need to copy the SAXHandler class file to the /purejsp/WEB-INF/classes/ directory, and the item.xml and the XMLExample.jsp to thepurejsp/ directory. Then load the following URL into your browser:http://yourserver:8080/purejsp/XMLExample.jspYou should see a page similar to Figure 15.2.Figure 15.2: Output from XMLExample.jsp.SummaryIn this chapter, we covered the basics of XML. We covered how to use Suns SAX parser. We also look atan example of how you would incorporate XML and JSPs. - 151 -In Chapter 16, JSP Communication with Servlets, you learn how you can use JSPs and servlets usingthe Model-View-Controller design pattern.Chapter 16: JSP Communication with ServletsOverviewIn this chapter we are going to discuss how you can incorporate servlets and JSPs using the Model-View-Controller design pattern (MVC). The MVC originated from Smalltalk and was used to design userinterfaces, wherein the application was made up of three classes: a Model, a View, and a Controller. Eachof these classes is defined in Table 16.1.Table 16.1: The Classes of the MVCClass DefinitionModel The Model represents the data or application object. It is what is being manipulated and presented to the user.View The View is the screen representation of the Model. It is the object that presents the current state of the Model.Controller The Controller defines the way the user interface reacts to the users input. The Controller is the object that manipulates the Model.The major benefit of using the MVC design pattern is that it separates the Views and Models. This makesit possible to create or change Views without having to change the Model. It also allows a Model to berepresented by multiple Views.A Servlet-Only Application ModelWhile servlets are a very sound technology and are excellent for server-side processing, they do havesome drawbacks when used alone. Two of the most common of these drawbacks are Servlets require an advanced level of Java understanding that HTML programmers usuallydo not have. Servlets generally require recompilation in order to change the client presentation layer.If we consider these servlet drawbacks, we can determine that one of the greatest strengths of servlets istheir server-side processing capability.A JSP-Only SolutionJavaServer Pages are also a very solid technology. Because JSPs are an extension of servlets, you cando just about anything with a JSP that you can with a servlet. As we have been discussing throughout thistext, one of the JSPs greatest strengths is its capability to separate content from presentation. The maindrawback with a JSP-only application model is that, as your application becomes more complicated, sodoes your scriptlet code. This results in confusing and difficult-to-maintain JSPs. If you plan on letting yourHTML programmers maintain your JSPs, which is very common, then they are going to have to have apretty good understanding of Java. This results in a very unclear definition of the programmers role. It alsocalls for a very skilled programmer.A Server-Side Implementation of the MVCThe real power of JSPs and servlets come into being when they are used together. In this section, wedefine a server-side implementation of the MVC, where the Model is a JavaBean, a shopping cart, thatrepresents the data being transmitted or received. The Controller is a servlet that manipulates or transmitsdata, and the View is a JSP that presents the results of the performed transaction. Figure 16.1 models thesteps involved in a server-side implementation of the MVC. - 152 - Figure 16.1: The steps in a server-side MVC. These steps are as follows:1. The Web browser makes a request to the Controller servlet.2. The servlet performs necessary manipulations to the JavaBean Model and forwards the result to the JSP View.3. The JSP formats the Model for display and sends the HTML results back to the Web browser. A Server-Side Example ...
Nội dung trích xuất từ tài liệu:
Java Server Pages: A Code-Intensive Premium Reference- P16 + (String)cfgTable.get(new String(ID)) + ); out.println(DESCRIPTION + + (String)cfgTable.get(new String(DESCRIPTION)) + ); out.println(PRICE + + (String)cfgTable.get(new String(PRICE)) + ); System.out.println(QUANTITY + + (String)cfgTable.get(new String(QUANTITY)) + );%> As you can see, there is really very little difference in the application code and the JSP code. The onlynoticeable differences are the way we load the XMLResource and the way we output the results. To seethis JSP run, you will need to copy the SAXHandler class file to the /purejsp/WEB-INF/classes/ directory, and the item.xml and the XMLExample.jsp to thepurejsp/ directory. Then load the following URL into your browser:http://yourserver:8080/purejsp/XMLExample.jspYou should see a page similar to Figure 15.2.Figure 15.2: Output from XMLExample.jsp.SummaryIn this chapter, we covered the basics of XML. We covered how to use Suns SAX parser. We also look atan example of how you would incorporate XML and JSPs. - 151 -In Chapter 16, JSP Communication with Servlets, you learn how you can use JSPs and servlets usingthe Model-View-Controller design pattern.Chapter 16: JSP Communication with ServletsOverviewIn this chapter we are going to discuss how you can incorporate servlets and JSPs using the Model-View-Controller design pattern (MVC). The MVC originated from Smalltalk and was used to design userinterfaces, wherein the application was made up of three classes: a Model, a View, and a Controller. Eachof these classes is defined in Table 16.1.Table 16.1: The Classes of the MVCClass DefinitionModel The Model represents the data or application object. It is what is being manipulated and presented to the user.View The View is the screen representation of the Model. It is the object that presents the current state of the Model.Controller The Controller defines the way the user interface reacts to the users input. The Controller is the object that manipulates the Model.The major benefit of using the MVC design pattern is that it separates the Views and Models. This makesit possible to create or change Views without having to change the Model. It also allows a Model to berepresented by multiple Views.A Servlet-Only Application ModelWhile servlets are a very sound technology and are excellent for server-side processing, they do havesome drawbacks when used alone. Two of the most common of these drawbacks are Servlets require an advanced level of Java understanding that HTML programmers usuallydo not have. Servlets generally require recompilation in order to change the client presentation layer.If we consider these servlet drawbacks, we can determine that one of the greatest strengths of servlets istheir server-side processing capability.A JSP-Only SolutionJavaServer Pages are also a very solid technology. Because JSPs are an extension of servlets, you cando just about anything with a JSP that you can with a servlet. As we have been discussing throughout thistext, one of the JSPs greatest strengths is its capability to separate content from presentation. The maindrawback with a JSP-only application model is that, as your application becomes more complicated, sodoes your scriptlet code. This results in confusing and difficult-to-maintain JSPs. If you plan on letting yourHTML programmers maintain your JSPs, which is very common, then they are going to have to have apretty good understanding of Java. This results in a very unclear definition of the programmers role. It alsocalls for a very skilled programmer.A Server-Side Implementation of the MVCThe real power of JSPs and servlets come into being when they are used together. In this section, wedefine a server-side implementation of the MVC, where the Model is a JavaBean, a shopping cart, thatrepresents the data being transmitted or received. The Controller is a servlet that manipulates or transmitsdata, and the View is a JSP that presents the results of the performed transaction. Figure 16.1 models thesteps involved in a server-side implementation of the MVC. - 152 - Figure 16.1: The steps in a server-side MVC. These steps are as follows:1. The Web browser makes a request to the Controller servlet.2. The servlet performs necessary manipulations to the JavaBean Model and forwards the result to the JSP View.3. The JSP formats the Model for display and sends the HTML results back to the Web browser. A Server-Side Example ...
Tìm kiếm theo từ khóa liên quan:
nhập môn lập trình kỹ thuật lập trình lập trình flash lập trình web ngôn ngữ html lập trình hướng đối tượngGợi ý tài liệu liên quan:
-
Đề cương chi tiết học phần Cấu trúc dữ liệu và giải thuật (Data structures and algorithms)
10 trang 316 0 0 -
Giáo trình Lập trình hướng đối tượng: Phần 2
154 trang 271 0 0 -
Kỹ thuật lập trình trên Visual Basic 2005
148 trang 262 0 0 -
NGÂN HÀNG CÂU HỎI TRẮC NGHIỆM THIẾT KẾ WEB
8 trang 203 0 0 -
101 trang 199 1 0
-
Giới thiệu môn học Ngôn ngữ lập trình C++
5 trang 193 0 0 -
Bài giảng Nhập môn về lập trình - Chương 1: Giới thiệu về máy tính và lập trình
30 trang 163 0 0 -
Luận văn: Nghiên cứu kỹ thuật giấu tin trong ảnh Gif
33 trang 152 0 0 -
Luận văn tốt nghiệp Công nghệ thông tin: Xây dựng website bán hàng nông sản
67 trang 138 0 0 -
Giáo trình nhập môn lập trình - Phần 22
48 trang 136 0 0