Escolar Documentos
Profissional Documentos
Cultura Documentos
Gouri Shankar
29 May 2003
Agenda
MVC Pattern
Brief about Servlets, JSP’s
About Struts
Using Struts – with examples
Pros / Cons
MVC Architecture
About Web Applications – handling dynamic
requests
About Servlets & JSP’s
Contd….
About Struts
Contd….
Struts in J2EE Environment
About Struts
Declarative exceptions
Programmatic exceptions
Tags in struts
<html> <body>
<html:form action="/logon" focus="username">
</html:form>
</body> </html>
Equivalent HTML
<html><body>
<form name="logonForm" method="POST" action="/struts-
example/logon.do"> </form>
<script language="JavaScript" type="text/javascript">
<!--
document.forms["logonForm"].elements["username"].focus()
// -->
</script> </body> <html> Contd….
Tag libs Examples
Example 2
<td>
<bean:write name="dept" property="name" />
</td>
Equivalent Code
<td>
<%=depts[index].getName()%>
</td>
Example 3
<title><bean:message key="title.message"/></title>
Contd….
Tag libs Examples
<td>
<html:link page="/listEmployees.do"
paramId="deptid"
paramName="dept" paramProperty="id">show
</html:link></td>
Equivalent Code
<td><a
href="EmployeeListing.jsp?deptid=<%=depts[i
ndex].
getId()%>">show
</a></td>
How does Struts fit in MVC ?
In View
– HTML / JSP,Custom taglibs, JavaScript, Style
Sheets, Message Bundles, ActionForm classes
In Controller
Advantages
– Server-side persistence of the form data
– Provides database support and includes JDBC connection pooling
capabilities
– Define multiple data sources in configuration file.
– Exception handling.
– Multiple actions handled in a single class.
– Dynamic action form generation.
– As the source code is available, we can extend framework to meet
user needs.
– Maintain multiple configuration files.
Disadvantages
– No vendor support
– Future compatibility with Struts in case of extension of framework
Other similar products in the market
– Velocity, Freemarker, WebMacro, Barracuda.
Some Do’s , Don’t’s
http://jakarta.apache.org/struts/
http://www.triveratech.com/downloads2/TriveraTe
ch_StrutsTutorial.PDF
http://www.onjava.com/lpt/a/2832
http://www.javaworld.com/javaworld/jw-04-
2003/jw-0418-struts_p.html
http://www.javaworld.com/javaworld/jw-02-
2002/jw-0201-strutsxslt_p.html
Questions & Answers
Thank You