Setup a Struts 2 application

8 January 2008

in 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.xml

The 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 \WEB-INF as:

<?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.

del.icio.us:Setup a Struts 2 application  digg:Setup a Struts 2 application  spurl:Setup a Struts 2 application  wists:Setup a Struts 2 application  simpy:Setup a Struts 2 application  newsvine:Setup a Struts 2 application  blinklist:Setup a Struts 2 application  furl:Setup a Struts 2 application  reddit:Setup a Struts 2 application  fark:Setup a Struts 2 application  blogmarks:Setup a Struts 2 application  Y!:Setup a Struts 2 application  smarking:Setup a Struts 2 application  magnolia:Setup a Struts 2 application  segnalo:Setup a Struts 2 application  gifttagging:Setup a Struts 2 application

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

Leave a Reply