Date: 2004-07-01T09:47:50
Editor: SteveRaeburn <[EMAIL PROTECTED]>
Wiki: Apache Struts Wiki
Page: StrutsMinimalInstall
URL: http://wiki.apache.org/struts/StrutsMinimalInstall
Formatting changes only (code sections)
Change Log:
------------------------------------------------------------------------------
@@ -9,7 +9,7 @@
So, simply add those to your WEB-INF/lib/ directory, and you have all the library
support you'll need for now.
Next, you need to set up WEB-INF/web.xml to use Struts' ActionServlet (ignore bogus
links in the following -- I cannot figure out how to do a proper code listing in this
Wiki):
-
+{{{
<web-app>
<display-name>Minimal Struts Application</display-name>
<description>Minimal Struts-based WebApp.</description>
@@ -23,9 +23,9 @@
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
-
+}}}
You also need to add one (that's right, just ''one'') extra configuration file,
WEB-INF/struts-config.xml:
-
+{{{
<struts-config>
<form-beans>
<form-bean name="nameBean" type="com.megginson.NameBean"/>
@@ -38,9 +38,9 @@
</action>
</action-mappings>
</struts-config>
-
+}}}
I created two JSPs. First, index.jsp, which contains a simple HTML form and no
special JSP logic at all (it could have been named index.html):
-
+{{{
<html>
<head>
<title>Servlet Test</title>
@@ -53,9 +53,9 @@
</form>
</body>
</html>
-
+}}}
The second JSP displays the output from the servlet, and uses a bit of ugly embedded
Java (yes, a tag library would have been cleaner); again, this is straight-forward,
non-Struts stuff:
-
+{{{
<html>
<head>
<title>Hello</title>
@@ -68,9 +68,9 @@
</body>
</html>
-
+}}}
Finally, I added two simple classes. The first one, com.megginson.NameBean, extends
the Struts ActionForm class, and is the bean that holds state information for the
request (Struts populates it automatically from the HTML form):
-
+{{{
package com.megginson;
import java.io.Serializable;
@@ -99,9 +99,9 @@
private String name;
}
-
+}}}
The second class, com.megginson.SubmitAction, is virtually useless in its current
state, but is here to show how the architecture works. It extends the Struts Action
class, and is invoked by the Struts ActionServlet:
-
+{{{
package com.megginson;
import javax.servlet.http.HttpServletRequest;
@@ -125,6 +125,6 @@
return mapping.findForward("success");
}
}
-
+}}}
And that's it: a simple Struts MVC app.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]