


Loading in 2 Seconds...
Loading in 2 Seconds...
Building Web Applications With The Struts Framework Session WE06 – 11/20/2002 – 10:00-11:00 Craig R. McClanahan Senior Staff Engineer Sun Microsystems, Inc. Session Outline. Web Applications Backgrounder The Model-View-Controller Architecture The Struts Framework
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
Building Web Applications With The Struts Framework
Session WE06 – 11/20/2002 – 10:00-11:00
Craig R. McClanahan
Senior Staff Engineer
Sun Microsystems, Inc.
public interface UserDatabase {
public User createUser(String username);
public void close() throws Exception;
public User findUser(String username);
public User[] findUsers();
public void open() throws Exception;
public void removeUser(User user);
public void save() throws Exception;
}
<%@ page contentType=”text/html;charset=”UTF-8” %>
<%@ taglib uri=”/WEB-INF/struts-bean.tld”
prefix=”bean” %>
<%@ taglib uri=”/WEB-INF/struts-html.tld”
prefix=”html” %>
<html:html locale=”true”>
<head>
<title>
<bean:message key=”logon.title”/>
</title>
<html:base/>
</head>
<body bgcolor=”white”>
<html:errors/>
<html:form action=”/logon” focus=”username”
onsubmit=”return validateLogonForm(this);”>
<table border=”0” width=”100%”>
<tr>
<th align=”right”> <bean:message key=”prompt.username”/>
</th>
<td align=”left”>
<html:text property=”username” size=”16”/>
</td>
</tr>
<tr>
<th align=”right”> <bean:message key=”prompt.password”/>
</th>
<td align=”left”>
<html:password property=”password”
size=”16”/>
</td>
</tr>
</table></html:form>
<html:javascript formName=”logonForm”
dynamicJavascript=”true”
staticJavascript=”false”/>
<script language=”Javascript” .../>
</body></html:html>
<struts-config>
<form-beans>
...
<form-bean name=”logonForm”
type=”org.apache.struts.action.DynaActionForm”>
<form-property name=”username”
type=”java.lang.String”/>
<form-property name=”password”
type=”java.lang.String”/>
</form-bean>
<form-bean name=”registrationForm”
type=”org.apache.webapp.example.RegistrationForm”/>
...
</form-beans>
<global-forwards>
<forward name=”logoff” path=”/logoff.do”/>
<forward name=”logon” path=”/logon.do”/>
<forward name=”registration”
path=”/registration.jsp”/>
<forward name=”success”
path=”/mainMenu.jsp”/>
</global-forwards>
<action-mappings>
<action path=”/editRegistration”
type=”org.apache.struts.webapp.example.EditRegistrationAction”
name=”registrationForm”
scope=”request” validate=”false”>
<forward name=”success”
path=”/registration.jsp”/>
</action>
<action path=”/saveRegistration”
type=”org.apache.struts.webapp.example.SaveRegistrationAction”
name=”registrationForm”
scope=”request” validate=”true”
input=”registration”/>
<action path=”/logon”
type=”org.apache.struts.webapp.example.LogonAction”
input=”request”
name=”logonForm”
scope=”request”/>
...
</action-mappings>
<controller>
<set-property property=”inputForward”
value=”true”/>
</controller>
<message-resources
parameter=”org.apache.struts.example.ApplicationResources”/>
<plug-in className=”org.apache.struts.webapp.example.memory.MemoryDatabasePlugIn”>
<set-property property=”pathname”
value=”/WEB-INF/database.xml”/>
</plug-in>
<plug-in className=”org.apache.struts.validator.ValidatorPlugIn”>
<set-property property=”pathnames”
value=”/WEB-INF/validator-rules.xml,
/WEB-INF/validation.xml”/>
</plug-in>
</struts-config>
<form-validation>
<formset>
<form name=”logonForm”>
<field property=”username”
depends=”minlength,...”>
<arg0 key=”prompt.username”/>
<arg1 key=”${var:minlength}”
name=”minlength”
resource=”false”/>
<var><var-name>minlength</var-name>
<var-value>3</var-value></var>
...
</field>
...
</form>
...
</formset>
</form-validation>
<web-app>
<servlet>
<servlet-name>Controller</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>
/WEB-INF/struts-config.xml
</param-value>
</init-param>
<load-on-startup> 1 </load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Controller</servlet-name>
<url-pattern> *.do </url-pattern>
</servlet-mapping>
...
</web-app>