Home Page Javascript Download Core Servlets & Java Server Java Cryptography Java in 60 Min A Day Javascript Tutorial About Us Contact Us
Site Search
Free Javascript Lessons
Newest Java Articles
Checkbox Changer
Check Entry
Check All
Block Key Press
Basic Validation
Auto Email Link
JavaScript Forms: Agree Before Entry
Auto Tab
JavaScript Calendars: Time Entered - Day Highlighted
JavaScript Calendars: Days Left
Related SE Keywords
Java virtual machine
Java Applet
Javascript Lesson
Javascript Tutorial
Java Programming
Java Games
Java Xml
Java String
Cryptography Extensions
Free Web Master Tools
JavascriptDownload.net > Free Javascript Lessons > Core Servlets & JavaServer Pages > 10- The Struts Framework: Basics / Setting Up Struts - Installing Struts - Making Your Own Struts Applications

10.2. Setting Up Struts

This section walks you through the process of downloading the Struts software, setting up your environment, and testing a simple application. Following, we cover Struts 1, specifically Struts 1.3. At the time of this writing, Struts 2 was still under development.

Core Note


This material covers the popular Apache Struts 1. At the time of this writing, Struts 2, based on WebWork, was still under development.

Installing Struts

In the following list, we quickly summarize the steps to install and configure Struts.

Download the Struts code. You can get the latest release build at http://struts.apache.org/downloads.html. You can get the source code, example applications, or the documentation, but all that is absolutely required is the struts-blank Web application. If you want to use the same Struts subrelease as our examples, just grab struts-blank.zip from the book's source code archive.

Update your CLASSPATH. To compile your Struts-based Web applications, add struts-core-1.3.5.jar to the CLASSPATH used by your compiler or IDE.

Bookmark the Struts documentation. You can access the documentation online at http://struts.apache.org/1.x/learning.html. Alternatively, you can download a copy of the documentation for local access.

The following subsections give details on each of these steps.

Downloading Struts

To use Struts, all you really need is a blank Web application to use as the starting point for your Struts-based apps. Struts is a library that works within a regular servlet and JSP environment; it is not a server or a new programming language. Therefore, if you have a template Web application with the appropriate JAR files, supporting files, and web.xml settings, you have Struts. That means that all you absolutely need to download is the struts-blank template Web application; nothing else is required. You can find the struts-blank template in the examples distribution, struts-1.3.5-apps.zip. The Apache Struts Web site also has a fuller distribution that includes a local copy of the documentation, examples, and source code, but this fuller distribution is optional, not required.

Grab the struts-blank-1.3.5 template from struts-1.3.5-app.zip or from the fuller distribution, struts-1.3.5-all.zip, at http://struts.apache.org/downloads.html. After downloading the .zip file, unzip it into a directory of your choice.

Updating Your CLASSPATH

To compile your Web applications, add struts-core-1.3.5.jar to the CLASSPATH used by your compiler or IDE (not by your server). This JAR file can be found in the lib directory of struts-blank-1.3.5, and is also in the lib directory of the fuller distribution.

Following are three possible ways to set your CLASSPATH.

  • Set the CLASSPATH in the startup file. For example, on Microsoft Windows, you would put the following lines in C:\autoexec.bat:

    set CLASSPATH=some-path\struts-core-1.3.5.jar;CLASSPATH%

    On UNIX or Linux, use your .cshrc, .bashrc, or .profile instead. For example, you would place the following in your .cshrc file (note that this all goes on one line with no spaces—it is broken here for readability):

    setenv CLASSPATH .:some-path/struts-core-1.3.5.jar:
  • Set the CLASSPATH through a system setting. On Microsoft Windows XP, go to the Start menu and select Control Panel, then System, then click the Advanced tab, then click the Environment Variables button. On Microsoft Windows 2000, go to the Start menu and select Settings, then Control Panel, then System, then Environment. Either way, enter the CLASSPATH value from the previous bullet.

  • Set the CLASSPATH in your editor or IDE. Most IDEs have a way of specifying the JAR files needed to compile projects. Or, you could make a small .bat file (Microsoft Windows) or shell script (UNIX/Linux) that supplies the struts-core-1.3.5.jar file as the argument to -classpath for javac.

Bookmarking the Struts Documentation

You can access Struts documentation on the Apache Web site or you can download a local copy from struts-1.3.5-docs.zip. The documentation includes a user's guide, FAQs, examples, and the API in Javadoc format. From the Apache Web site, you can find the documentation online at http://struts.apache.org/1.x/learning.html. If you downloaded the fuller Struts distribution, struts-1.3.5-all.zip, you can find the Struts documentation at struts_install_dir/docs. Either way, we strongly recommend you bookmark the documentation for easy access.

Testing Struts

After downloading Struts, you should test it with your servlet engine. To do so, all you need to do is install the struts-blank Web application. Here are the basic steps:

Install struts-blank on your server. Put a copy of struts-blank-1.3.5.war in your server's Web application autodeploy directory. For Apache Tomcat, you can install the application by copying the file to tomcat_install_dir/webapps/. Alternatively, use jar -xvf (or WinZip) to extract the files and copy them tomcat_install_dir/webapps/.

Start the server. Most servers automatically recognize newly deployed Web applications and do not require a restart if they are already running when you deploy struts-blank.

Access the struts-blank application. Access the application through http://localhost/struts-blank-1.3.5/. This URL assumes you are running the server on your desktop and the server is using port 80. In general, you would access the application through http://hostname:port/struts-blank-1.3.5/ (for Struts version 1.3.5). If successful, you should see a Web page similar to the one shown in Figure 10-1.

Making Your Own Struts Applications

To make your own Struts application, you need the appropriate JAR files, TLD files, XML files, properties files, and web.xml entries. Because struts-blank-1.3.5 already has all of these files, the simplest strategy is to copy and rename struts-blank-1.3.5 or some previous Web application that was derived from struts-blank. So, your development process typically looks like this:

Copy the struts-blank-1.3.5 directory to your development area.

Rename it whatever you want to call your Web application (say, my-struts-app).

Add code for your application. Remove index.jsp and pages/Welcome.jsp. Remove any commented out or irrelevant entries in struts-config.xml.

Copy to your server's Web application deployment directory (e.g., the webapps directory for Tomcat).

Start the server and access http://localhost/my-struts-app/path, where path corresponds to a file or .do address you created in the application.

Adding Struts to an Existing Web Application

Adding Struts capabilities to existing Web applications is a huge undertaking and will probably require several attempts to get it right. Assuming that your Web application is in the directory your_web_app, here is a quick summary of the steps you would take.

Copy the JAR files. Copy the JAR files from struts-blank-1.3.5/WEB-INF/lib to your_web_app/WEB-INF/lib. There should be about 10 of them, but this can vary in Struts subreleases.

Copy the Struts configuration file. Copy struts-config.xml from struts-blank-1.3.5/WEB-INF to your_web_app/WEB-INF.

Copy the properties file. Copy MessageResources.properties from struts-blank-1.3.5/WEB-INF/classes to your_web_app/WEB-INF/classes.

Copy the Tiles and Validator configuration file. If you plan on using the Validator plug-in, copy validation.xml from struts-blank-1.3.5/WEB-INF to your_web_app/WEB-INF. If you plan on using the Tiles plug-in, copy tiles-def.xml from struts-blank-1.3.5/WEB-INF to your_web_app/WEB-INF.

Copy the deployment descriptor declarations. Copy the declarations out of struts-blank-1.3.5/WEB-INF/web.xml into your_web_app/WEB-INF/web.xml.

This is a huge pain; don't bother! Start with struts-blank-1.3.5 (or a previously created Web app based on struts-blank) instead.

Add Comment
homepage   |  about us  |  contact us
Powered By teknonova.com Sunucu Kiralama