Professional Documents
Culture Documents
Building Web Applications
Building Web Applications
[Reenskaug 2006|
Can we use a conventional design?
Can we use a conventional design?
Can we use a conventional design?
Can we use a conventional design?
Can we use a conventional design?
Desktop MVC
View pulls state
All three components interconnected
Enterprise MVC
Controller pushes state
Controller connects View with Model
Why bother?
For a small application, don't
For a large application, MVC ...
Helps page share code
Encapsulates navigation
Document Root
*.html, *.jsp
JSP tags
WEB-INF (Web Application Infrastructure)
web.xml (Web Application Deployment Descriptor)
Servlets, Filters, Listeners, Security Descriptors
lib
*.JAR (Java Archive)
classes
*.class, *.properties, *.tld (tag library descriptor)
How are web applications organized?
Review
(1) CGI (a) Tag Library Descriptor
(2) WEB-INF (b) Java Archive
(3) web.xml (c) Web Application Infrastructure
(d) Computer Gateway Interface
(4) JAR
(e) Web Application Deployment
(5) TLD Descriptor
Review
(1) CGI (d) Computer Gateway Interface
(2) WEB-INF (c) Web Application Infrastructure
(3) web.xml (e) Web Application Deployment
Descriptor
(4) JAR (b) Java Archive
(5) TLD (a) Tag Library Descriptor
Review
To place a resource on the classpath,
you can place it under the ******* folder.
Review
To place a resource on the classpath,
you can place it under the classes folder.
Building Web Applications
Why web applications?
Can we use a conventional design?
How are web applications organized?
What value does Struts 2 add?
What value does Struts 2 add?
Struts
The nearly invisible pieces that hold up
buildings, houses, and bridges.
What value does Struts 2 add?
Custom tags
Action handler
Result handler
What value does Struts 2 add?
Custom tags
Render dynamic content
Action handler
Result handler
What value does Struts 2 add?
Custom tags
Render dynamic content
Action handler
Interacts with other layers
Result handler
What value does Struts 2 add?
Custom tags
Render dynamic content
Action handler
Interacts with other layers
Result handler
Dispatches to server page, HTML, PDF, ...
What value does Struts 2 add?
Custom tags
Render dynamic content (View)
Action handler
Interacts with other layers (Model)
Result handler
Dispatches to server page (Controller)
Hello.jsp
<%@ taglib prefix="s" uri="/tags" %>
<html>
<body>
<h2><s:text name="message"/></h2>
</body>
</html>
Hello.properties
message = Congratulations! Struts is up and running ...
# Add your messages here ...
Hello_es.properties
message = ¡Struts está bien! ...
# Add your messages here ...
struts.xml
<struts>
<package name="default" extends="struts-default">
<action name="Hello">
<result>/Hello.jsp</result>
</action>
<!-- Add your actions here -->
</package>
</struts>
Hello World!
Hello.jsp
<h3>Options</h3>
<ul><li>
<s:url id="en" action="Hello">
<s:param name="request_locale">en</s:param>
</s:url>
<s:a href="%{en}">English</s:a>
</li><li>
<s:url id="es" action="Hello">
<s:param name="request_locale">es</s:param>
</s:url>
<s:a href="%{es}">Español</s:a>
</li></ul>
Pick your Poison!
What does Struts 2 add?
user.name getUser().getName()
user.toString() getUser().toString()
****** *******
Result handler