The choice of pure JSP or pure Servlet design site has its limitations, Struts is a powerful tool to link them together. Using Struts to develop an application based on MVC pattern, the concept of MVC can be found in GoF's design pattern--the foundation of reusable object-oriented software.
What you need to do now is download, install, configure the following tools, different versions of the operation may have some differences, the specific look at their documents:
Tomcat 4.1.24
Apache 2.0.43, W/mod_jk2 2.0.43
Java 2 SDK Standard Edition 1.4.0
Struts 1.1
Eclipse 2.1.0
Struts is written in Java, which requires JDK 1.2 or later. If you're using JDK 1.4, like me, XML Parser and JDBC 2.0 Optional Package Binary have been included by default.
New projects
In this routine we want to develop a simple Web application that allows users to log in and log off. For simplicity, the data is set to constant rather than stored in the database, after all, this is about Struts, not Java.
First create a directory in your Tomcat configuration's application home directory, say Logonapp. Create directory src and Web-inf in Logonapp, create directories classes and Lib in Web-inf, copy Struts.jar to lib directories from the distribution of Struts, and copy $CATALINA _home/com Mon/lib/servlets.jar to Lib directory. Copy all struts*.tld to Web-inf directory from the distribution of Struts.
Now open Eclipse, you will see four view. Now we're going to build a new project, click File-> New Project, open a window, select Java in the first pane, select Java Project in the second pane, and click Next. Enter the name of the project (in order to remember, also known as Logonapp bar), remove the Use default checkbox check box, browse to the Logonapp directory, click Next. A new window appears, click Add Folder on the Source tab, add $APP _base/src, fill in the Default output Folder $APP _base/web-inf/classes, click Finish. Click Window-> Open Perspective-> Resource to see if the. project file has automatically included all jar files in the Lib directory.
Your logonapp/web-inf/web.xml should look like the following:
<?xml version= "1.0"
<! DOCTYPE web-app
Public "-//sun Microsystems, INC.//DTD Web application 2.3//en"
"http://java.sun.com/j2ee/dtds/ WEB-APP_2_3.DTD
<web-app>
<!--Action Servlet Configuration
<servlet>
< Servlet-name>action</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>
<!--Action servlet Mapping
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</ Servlet-mapping>
<!--the Welcome File List;
<welcome-file-list>
<welcome-file> Index.jsp</welcome-file>
</welcome-file-lIst>
<!--Struts Tag Library descriptors;
<taglib>
<taglib-uri>/web-inf/ Struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/web-inf/struts-html.tld</taglib-uri>
< Taglib-location>/web-inf/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/web-inf/struts-logic.tld</taglib-uri>
<taglib-location>/web-inf/ Struts-logic.tld</taglib-location>
</taglib>
</web-app>