Setup a Struts 2 application
8 January 2008in this post, I will write about how to setup a Struts 2 application from scratch. This will be interesting for the developer who are using Struts for the very first time.
Download the latest struts framework from the http://struts.apache.org. To get started with a new application you can setup a web infrastructure from scratch.
Setup the Web Application File Structure as follows within webapps folder. (This tutorial assumes that you are using Apache Tomcat as a web server, and webapps folder is the folder within Tomcat folder).
\MyStrutsFolder\
\MyStrutsFolder\META-INF\
\MyStrutsFolder\WEB-INF\
\MyStrutsFolder\WEB-INF\classes\
\MyStrutsFolder\WEB-INF\lib\
\MyStrutsFolder\WEB-INF\lib\minimum JARs + any plugin JARs + plugin dependencies
\MyStrutsFolder\WEB-INF\web.xmlThe following files are a minimum requirement for your application.
Copy to your webapps/lib directory the required JARs from struts framework folder (say \struts-2.0.11-all\struts-2.0.11\lib):
struts2-core.jar
xwork.jar
ognl.jar
freemarker.jar
commons-logging.jar
and any Struts plugin JARs or any plugin dependencies.
Create an web.xml file in
<?xml version="1.0"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <display-name>My Application</display-name> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
Create a skeleton struts.xml file in \WEB-INF\classes as .
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts><!-- Configuration for the default package. --> <package name="default" extends="struts-default"> ... </package> </struts>
This is sample setup for your struts application.
Related Posts:
Top Of Page | Trackback
If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.
It will look like this: Setup a Struts 2 application