Choosing pure JSP or a pure servlet design site has its limitations, and Struts is a powerful tool that links them together. The Struts can develop MVC mode-based applications, and the concept of MVC can see GOF's "design mode - the basis for object-oriented software". What you have to do now is, download, install, configure the following tools, version different words may be some differences, specific to their documentation:
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 should require JDK 1.2 or higher. If you use JDK 1.4, just like me, XML Parser and JDBC 2.0 Optional package binary have been included in the default. New projects In this routine we have to develop a simple web application, allowing users to log in and log out. Simply put, the data is set to constants, not in the database, after all, Struts is Struts, not Java. First create a directory in your Tomcat Configuration, for example, logoApp. Create a directory SRC and Web-INF in LogonApp, create directory classs and libs in Web-INF, copy struts.jar to lib directory from Struts distribution, and copy $ catalina_home / common / lib / servlets.jar to LiB directory. Copy all struts * .tld to the web-inflicity from the Struts distribution. Now open Eclipse, you will see four views. Now we have a new project, click File -> New Project, open a window, select Java in the first pane, select Java Project in the second pane, click Next. Enter the project name (for a good memory, you are also called LogonApp), remove the check box of the USE DEFAULT check box, browse to the logoApp directory, click Next. A new window appears, click Add Folder on the Source Tab, add $ app_base / src, fill in $ app_base / web-inf / classes in Default Output Folder, click Finish. Click on Window -> Open Perspective -> Resource to see if the .project file has automatically contain all JAR files in the lib directory.
Your logonapp / web-inf / web.xml should look like this: XML Version = "1.0"?> - // Apache Software Foundation // DTD STRUTS Configuration 1.1 // en "" http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd "> Prefix = "bean"%> <% @ taglib URI = "/ Web-inf / struts-html.tld" prefix = "html"%> package org.monotonous.struts; import java.util.Locale; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action. Action; import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache .struts.action.ActionMapping; import org.apache.struts.util.MessageResources; import org.apache.commons.beanutils.PropertyUtils; public final class LogonAction extends Action {public ActionForward execute (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {Locale locale = getLocale (request); MessageResources messages = getResources (request); // Validate the request parameters specified by the user ActionErrors errors = new ActionErrors (); String username = (String) PropertyUtils.getSimpleProperty (form , "username"); string password = (string) PropertyUtils.getsimpleproperty (Form, "Password"); if ((UserName! = "foo") || (Password! = "bar") Errors.Add (ActionerRRORS. GLOBAL_ERROR, new ActionError ( "error.password.mismatch")); // Report any errors we have discovered back to the original form if) {saveErrors (request, errors) (errors.isEmpty (!); return (mapping.getInputForward ());} // save our logged -in user in the session httpsession session = request.getations (); // DO Something with session ... // remove the obsolete formle i (mapping.getattribute ()! = NULL) {IF ("Request" .Equals (mapping.getscope ())))))); mapping.getattribute ());