Struts Agenda n n Preface Struts and its

  • Slides: 15
Download presentation
Struts

Struts

Agenda n n Preface Struts and its components An example The architecture required for

Agenda n n Preface Struts and its components An example The architecture required for Struts Applications

Preface Problem we faced when designing JSP: n Familiar with HTML and expertise in

Preface Problem we faced when designing JSP: n Familiar with HTML and expertise in web design (the content, font, color, web page layout etc. ) n Having Programming knowledge with Java (embedded java code in JSP)

Break down the tasks with Struts

Break down the tasks with Struts

What is Struts n n n Norwegian word meaning ostrich A Java open source

What is Struts n n n Norwegian word meaning ostrich A Java open source framework especially used for web application development. With Struts, developers can following the MVC design pattern to design web application

What is MVC design pattern n n Input Controller Processing Model Calculation, database operation,

What is MVC design pattern n n Input Controller Processing Model Calculation, database operation, connection with remote systems Output View Application screen, web pages

Controller in Struts n n Called Action. Servlet Its functions: - Receive http request

Controller in Struts n n Called Action. Servlet Its functions: - Receive http request from client (Web browser) - Invoke Model part by calling Action objects - Send the JSP file returned by Action objects back to the client

Model component in Struts n n In Action objects Its functions: - Carrying out

Model component in Struts n n In Action objects Its functions: - Carrying out business related processing (by itself or other objects) - Determining the next web page to send to the client

View component in Struts n n Html and JSP files with Struts tags embedded

View component in Struts n n Html and JSP files with Struts tags embedded Features provided by Struts tags: - Sophisticated html form handling (validation, error display etc. ) - Display localized messages stored in a resource file on web page (message tag) - And many others …

How to get M V C parts work together n n n A configuration

How to get M V C parts work together n n n A configuration file called struts-config. xml in XML format Defines Action classes, Java Beans used in the project Define “virtual” paths to be used in JSP files

An example In Test. Web 1. jsp: …<struts-html: form action=“action 1”>… In struts-config. xml:

An example In Test. Web 1. jsp: …<struts-html: form action=“action 1”>… In struts-config. xml: … < action path=“action 1” type=“Java. Bean 1”…>… <forward name=“next 1" path="/nextpage 1. jsp"/> n If changing to use another java bean as Action class in the future, …

The whole process of a client request Call “action 1” Client request Action. Servlet

The whole process of a client request Call “action 1” Client request Action. Servlet Action. Forward find JSP / HTML files nextpage 1. jsp next 1 Action object Java. Bean 1

The architecture required for Struts Applications Struts classes / Taglib Java Application Server JSP

The architecture required for Struts Applications Struts classes / Taglib Java Application Server JSP / Servlet engine

Summary n n Breakdown web development into MVC parts Easy to develop and maintain

Summary n n Breakdown web development into MVC parts Easy to develop and maintain

Questions?

Questions?