Complete Guide to struts development in eclipse

Source: Internet
Author: User
1. Prepare the installation program

1. Download the JDK 5.0 Installer

After agreeing to the agreement, you can download jdk-rj5_0_05-windows-i586-p.exe.

2. Download Tomcat 5.5.9

: Http://

The latest version is 5.5.11alpha. As it is a test version, there may be some uncertainties. Therefore, we will download 5.5.9 EXE here.

3. Download sysdeo eclipse Tomcat launcher 3.1beta

: Http://


4. Download the eclipse 3.1 installation program

: Http://

The corresponding version of jdt is required here. If the eclipse SDK version is downloaded, the download link of jdt is available in the back part of the same download page, after the download, copy the corresponding files to the corresponding folder under the eclipse installation directory.

Here we download

5. Download the GEF 3.1 Installer



Index. php

Here we download

6. Download the eclipse HTML editor 1.6.7 Installer

: Https:// Amp; release_id = 16537



7. Download The strutside 1.1.7 Installer

: Https:// Release_id = 16537 #16537


Now we have prepared all the installation packages.

2. Install JDK and configure the development environment

Double-click the EXE file of the JDK installation package and install it as prompted. After the installation is complete, set the bin folder in the JDK installation directory to the path of the environment variable. At the same time, set the Rt. jar package under the lib directory of jre to the classpath of the environment variable.

Here we install JDK under the default installation path C:/program files/Java/jdk1.5.0 _ 02. I will not talk about it here. I can find many articles on JDK installation and configuration on the Internet.

3. Install the Tomcat server

Double-click the EXE file of the tomcat installation package and install it as prompted. Here, the installation directory is D:/tomcat5.5 and the administrator password is set to 12345678.

4. Install eclipse development tools

Only extract the installation package, and cut the eclipse folder to the directory you want to place. Here, we will install eclipse under the D:/eclipse directory.

In the installation directory, double-click the eclipse.exe file to start eclipse. In the middle, you will be asked about the default working directory. You can set the working directory by default or by yourself. Here, you can set it to E:/workspace directory. Select the use this as the default and do not ask again option.

Eclipse has been installed successfully.

5. Install the tomcatplugin plug-in

The installation is simple. decompress the downloaded package and copy the decompressed com. sysdeo. Eclipse. tomcat_3.1.0.beta folder to the Directory D:/Eclipse/plugins. We turn off the already opened eclipse and re-open it. OK. Now we will find that there are several male icons in the toolbar, that is, the Tomcat start, stop, and restart buttons. Open the window/preferences of eclipse, and we can find tomcat in the tree on the left.

Click tomcat, select version 5.x on the right, and set Tomcat home to D:/tomcat5.5, and contexts directory to D:/tomcat5.5/CONF/Catalina/localhost. Tomcat plugin has been set up.

6. Install the GEF plug-in

In the same example, decompress and copy the three folders in the decompressed eclipse directory to the D:/eclipse directory to overwrite all existing folders.

Now, the installation of GEF is complete.

7. Install the eclipse HTML editor plug-in

Decompress the package and copy the Plugins directory to the D:/eclipse directory to overwrite the original folder. The eclipse HTML editor plug-in has been installed.

8. Install the strutside plug-in

Decompress the package, and copy the Plugins directory to the D:/eclipse directory to overwrite the original folder.

Now, the strutside plug-in has been installed.

6. Create an action object

The process of creating a form is the same as that of creating a form. is. action package. In the same process, open the new Wizard and select struts action to create loginaction. java class, select the default value. We edit loginaction as follows:

          package; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import; public class LoginAction extends Action { private static final long serialVersionUID = 1L; public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,HttpServletResponse response) throws Exception { // this line is here for when theinput page is upload-utf8.jsp, // it sets the correct characterencoding for the response String encoding = request.getCharacterEncoding(); if ((encoding != null) && (encoding.equalsIgnoreCase("GB2312"))){ response.setContentType("text/html; charset=GB2312"); } else { response.setContentType("text/html; charset=GBK"); } try { if (form instanceof LoginForm) { LoginForm theForm = (LoginForm) form; if(theForm.getUsername().equals("user") && theForm.getPassword().equals("123456")) { return new ActionForward("/"); } else {                           return new ActionForward("/"); } } } catch (Exception e) { } // this shouldn't happen in this example return null;    } }

Note that here is the direct use of actionforward to turn, you can also follow the blank routines provided by struts in the struts-blank.war of the practice of steering, you can compare there will be a harvest.

7. logon creation successful page

The creation of the index. jsp page is the same as that of the creation of the welcome. jsp page. The default settings are used. Edit the content as follows:

          <% @ Page pageencoding = "GBK" contenttype = "text/html; charset = GBK "%> <HTML> 

8. Add configuration in Struts-config.xml

Add the configuration of formbean, in

And labels:

          <form-bean name="loginForm" type=""/>

Add the JSP file ing inAnd labels:

          <action path="/index" forward="/index.jsp"/> <action path="/welcome" forward="/welcome.jsp"/>

Add the action file ing, inAnd labels:

         path="/logincheck" type="" name="loginForm" scope="request" validate="true"/>

The modified struts-config.xml goes roughly as follows:

          <?xml version="1.0"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"""> <struts-config> <data-sources> </data-sources> <form-beans> <form-bean name="loginForm" type=""/> </form-beans> <global-exceptions> </global-exceptions> <global-forwards> </global-forwards> <action-mappings> <action path="/index" forward="/index.jsp"/> <action path="/welcome" forward="/welcome.jsp"/>    <action path="/logincheck" type="" name="loginForm" scope="request" validate="true"/> </action-mappings>  <controller processorClass= "org.apache.struts.tiles.TilesRequestProcessor"/> <message-resources parameter="MessageResources"/> <plug-in className="org.apache.struts.tiles.TilesPlugin"> <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml"/> <set-property property="moduleAware" value="true"/> </plug-in> <plug-in className="org.apache.struts.validator.ValidatorPlugIn"> <set-property property="pathnames"value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/> </plug-in> </struts-config>

Now we can run the test program.

9. Run the test program

Right-click the root directory of the testweb project and choose "initialize ate project"> "Update context definition" from the menu to deploy the project to Tomcat. A message is displayed, indicating that the operation is successful.

Click the Tomcat icon in the menu bar to start Tomcat, and enter http: // localhost: 8080/testweb/index. Do In the IE address bar. The page content of index. jsp is displayed.

9. Create a test project

If you have completed all the preceding steps, you can restart eclipse to make the newly installed plug-in take effect and start development.

1. Use sysdeo Tomcat plugin to create a tomcat project:

File-> New-> others, open the new wizard dialog box, find Java-> Tomcat projects in the tree, select, and click Next. Enter textweb in projects name, select use default, and click Next. On the next dialog page, keep the default settings and click finished. In this case, the new project testweb is displayed in the package explorer of Eclipse.

2. Add Struts Framework

File-> New-> others, open the new wizard dialog box, find amateras-> Struts-> Add struts support, and click Next.

Keep the default settings and click Finish. At this time, in eclipse package Explorer will see a lot of struts library files added, In the WEB-INF also added a lot of struts configuration files. Now we have added the Struts framework to the project.

3. Edit struts-config.xml files

In the WEB-INF folder, right-click the menu and choose open with-> amateras XML editer to edit the XML text directly, select open with-> struts-config.xml editor to edit files in graphic mode.

Click the corresponding struts object in outline on the right to add a new object. Here we just show that there is a more convenient struts-config.xml file editor, we will develop a simple applet later.

4. Create a new page index. jsp

File-> New-> others, open the new wizard dialog box, find amateras-> JSP file, click Next, change filename to index. jsp, and click Finish. Open the index. jsp file and edit the file as follows:

          <% @ Page pageencoding = "GBK" contenttype = "text/html; charset = gb2312 "%> <HTML> 

5. Create a form data object

Open the file-> New-> package dialog box, enter com. Is. Form in name, and click Finish. Find the package you just created in the package explorer tree on the right, right-click COM. is. in the form package, choose new> others from the menu, find amateras> struts action form, click Next, enter loginform in the name column of the dialog box, and click Finish.

Edit the content of the loginform class as follows:

          package;import org.apache.struts.action.ActionForm;public class LoginForm extends ActionForm {private static final long serialVersionUID = 1L;private String username = "";private String password = "";/*** @return Returns the password.*/public String getPassword(){return password;} /*** @param password The password to set.*/public void setPassword(String password){ this.password = password;}/*** @return Returns the username.*/public String getUsername() {return username;}/*** @param username The username to set.*/public void setUsername(String username) {this.username = username;}}

Note: The two attributes here correspond to the names of the two input controls in form in JSP respectively. Why? You can go to the struts help document and I will not elaborate on it, after the Form class finishes writing the attributes, the get and set methods can be automatically generated using the commands in the eclipse source. In the context menu, I will not go into details. Go to the Internet to check the information, there are many documents about how to use eclipse.


Source: PHPSESSID = d7adc05057545d417e9f6ef3fe8d607d

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.