Eclipse Development Struts Complete guide

Source: Internet
Author: User
Tags add config final string version variable win32 root directory
First, prepare to install the program

1, JDK 5.0 installation program Download

Download Address:

       
        
         
        Https://jsecom15b.sun.com/ECom/EComActionServlet/DownloadPage:~:com.sun.sunit.sdlc.content.DownloadPageInfo; Jsessionid=502e87c71d77e3bc297c08b35dac9ad4;jsessionid=502e87c71d77e3bc297c08b35dac9ad4
       
        

After agreeing to the agreement, you can download Jdk-1_5_0_05-windows-i586-p.exe.

2, tomcat 5.5.9 download

Download Address: http://jakarta.apache.org/site/downloads/downloads_tomcat-5.cgi

The latest version is the 5.5.11alpha version, because it is beta, so there may be uncertainties, so we download the 5.5.9 exe here.

3. Sysdeo Eclipse Tomcat Launcher plugin 3.1beta download

Download Address: Http://www.sysdeo.com/eclipse/tomcatplugin

Download Tomcatpluginv31beta.zip here.

4. Eclipse 3.1 Installer Download

Download Address: http://www.eclipse.org/downloads/index.php

This requires the corresponding version of the JDT, if you download the Eclipse SDK version, if not, if not, the back part of the same download page has a jdt download link, download the corresponding files are copied into the Eclipse installation directory under the corresponding folder.

Here we download eclipse-sdk-3.1-win32.zip.

5, GEF 3.1 installation program download

Download Address:

http://download.eclipse.org/tools/gef/downloads/drops/R-3.1-200507071758/

index.php

Here we download gef-all-3.1.zip.

6. Eclipse HTML Editor 1.6.7 Installer Download

Download Address: https://sourceforge.jp/projects/amateras/files/?release_id=16537

#16537

Here we download: Tk.eclipse.plugin.htmleditor_1.6.7.zip.

7, strutside 1.1.7 installation program Download

Download Address: https://sourceforge.jp/projects/amateras/files/?release_id=16537#16537

Here we download: Tk.eclipse.plugin.struts_1.1.7.zip.

All right, here we have all the installation packages ready.

Second, install the JDK and configure the development environment

Here you only need to double-click the JDK installation package EXE file, follow the prompts to install. After the installation is complete, set the Bin folder in the JDK installation directory into the path path of the environment variable. At the same time, the Rt.jar package under the Lib directory of the JRE is set into the classpath of the environment variable.

Here we install the JDK to the default installation path C:\Program files\java\jdk1.5.0_02. Here is not much to say, the Internet can search for a number of JDK installation configuration articles.

Third, the installation of Tomcat server

Just double-click the Tomcat installation package EXE file, follow the prompts to install, here our installation directory is D:\Tomcat5.5, the administrator password set to 12345678.

Iv. Installing Eclipse Development tools

Just unzip the Eclipse-sdk-3.1-win32.zip installation package and cut the Eclipse folder inside to the directory you want to place, where we install eclipse into the D:\eclipse directory.

You can start eclipse by double-clicking the Eclipse.exe file under the installation directory. The middle will ask the default working directory, you can set it by default, or you can set the working directory, set to E:\workspace directory. Please select the use this as the "not" ask again option so that it will not be asked again after startup.

To this eclipse installation was successful.

V. Installation of Tomcatplugin Plug-ins

Installation is very simple, unzip the installation package we have downloaded Tomcatpluginv31beta.zip, the Unpacked Com.sysdeo.eclipse.tomcat_3.1.0.beta folder copy to D:\eclipse\ The plugins directory can be. We turn off the eclipse that's already open, turn it back on, OK, and now we'll see a few more Tomcat icons on the toolbar, the Tomcat's start, stop, and reboot buttons. By opening Eclipse's window/preferences, we can also find Tomcat in the tree on the left.

Click Tomcat, and on the right we select version 5.x, and then set Tomcat home for d:\tomcat5.5,contexts directory for D:\Tomcat5.5\conf\Catalina\ localhost To this Tomcat plugin setup is complete.

VI. Installation of GEF Plug-ins

Again, unzip the gef-all-3.1.zip and then copy the three folders in the extracted Eclipse directory into the D:\eclipse directory, overwriting all existing folders.

OK, here's the GEF installation complete.

Eight, create a test project

If you have completed all of the above steps, you can now restart eclipse so that the newly installed plug-ins will take effect and begin to develop formally.

1, use Sysdeo Tomcat plugin to create the Tomcat project:

File->new->others, Open the New Wizard dialog box, find Java->tomcat in the tree Projects, select and click the Next button. Enter Textweb in Projects name, select Use default, and click Next. On the next dialog page, leave the default setting and click Finished. At this point, we will see the new project TestWeb in Eclipse's Package explorer, and create the completion.

2, join the Struts framework

File->new->others, Open the New Wizard dialog box, find Amateras->struts->add Struts Support, Select the Click Next button.

Leave the default setting and click the Finish button. At this point, in Eclipse's Package explorer, you'll see a lot of struts-added libraries, and a lot of struts profiles under Web-inf. To this we have joined the Struts framework in the project.

3, edit the Struts-config.xml file

can be found under the Web-inf folder, right-click the menu to select Open With->amateras XML editer can directly edit the XML text, Select Open With->struts-config.xml Editor to edit the file in graphics mode.

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

4, create a new page index.jsp

File->new->others, Open the New Wizard dialog box, locate amateras->jsp File, click the Next button, FileName changed to index.jsp, click Finish. Then open the index.jsp file for editing, which reads as follows:

 
       
         <% @page pageencoding= "GBK" contenttype= "text/html"; char set=gb2312 "%> 

5, create a form data Object

Open the File->new->package dialog box, enter Com.is.form in name, and click the Finish button. Find the package you just created in the Package Explorer tree on the right, right-click the Com.is.form package, new->others in the menu, and find the amateras->struts->struts Action Form, Click Next, enter LoginForm in the Name column of the dialog box, and click the Finish button. The contents of the

Edit LoginForm class are:

       
        
         
        Package Com.is.form;import Org.apache.struts.action.actionform;public Class LoginForm extends Actionform {private  Static final Long Serialversionuid = 1l;private string username = "";p rivate string password = "";/*** @return Returns the Password.*/public String GetPassword () {return password.}/*** @param password the password to set.*/public void Setpasswo RD (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 that the two attributes here correspond to the names of the two input controls in the form in our JSP, and why we can go to the help document of struts, and I will not elaborate on that, and after the form class has finished writing the attributes, The Get and set methods can be generated automatically by the commands in Eclipse's source, and in the right-click menu, go to the web and look up the data, and there's a lot of documentation about eclipse usage.

Seven, install the Eclipse HTML Editor plug-in

Unzip the Tk.eclipse.plugin.htmleditor_1.6.7.zip package, and then copy the plugins directory to D:\ Overwrite the original folder under the Eclipse directory. To this Eclipse HTML Editor plug-in installation is complete.

Eight, install the Strutside plug-in

Extract the Tk.eclipse.plugin.struts_1.1.7.zip package, and then copy the plugins directory to the D:\eclipse directory to overwrite the original folder.

OK, to this strutside plug-in installation complete.

6, creating the Action object

is the same procedure as creating a form, we just create a new com.is.action package, the same process, open the New wizard, just select the Struts Action, Create the Loginaction.java class with the default values selected. We edited loginaction for the following:

       
        
Package com.is.action; 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 Com.is.form.LoginForm; public class Loginaction extends Action {private static final long serialversionuid = 1L; public Actionforward Execute (Ac  tionmapping mapping, Actionform form, HttpServletRequest request,httpservletresponse response) throws Exception {//This Line are here in 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 ("/welcome.do?type=true"); else {return new Actionforward ("/welcome.do?type=false");}    The catch (Exception e) {}//This shouldn ' t happen to example return null; } }
       

Note that this is done directly with Actionforward, you can also follow the instructions in the blank routine Struts-blank.war provided in struts, and you can compare the gains.

7. Create Login Success Page

As with creating index.jsp pages, we create welcome.jsp pages with the default settings. and edit its contents as follows:

       
        
         
        <% @page pageencoding= "GBK" contenttype= "text/html; CHARSET=GBK "%>

8, increase the configuration in the Struts-config.xml

Add the configuration of the Formbean, adding between and tags:

       
        
         
        <form-bean name= "LoginForm" type= "Com.is.form.LoginForm"/>
       
        

Add a mapping for the JSP file, adding between and tags:

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

Add the mapping of the action file, adding between and tags:

       
        
         
        Path= "/logincheck" type= "com.is.action.LoginAction" name= "LoginForm" scope= "Request" validate= "true"/>
       
        


The modified Struts-config.xml is roughly as follows:

       
        
<?xml version= "1.0"?> <! DOCTYPE struts-config Public "-//apache Software foundation//dtd struts Configuration 1.2//en" "http:// Struts.apache.org/dtds/struts-config_1_2.dtd "> <struts-config> <data-sources> </data-sources > <form-beans> <form-bean name= "LoginForm" type= "Com.is.form.LoginForm"/> </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= "com.is.action.LoginAction" 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" /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>
       

We can run the test program here.

9. Run test program

Right-click the TestWeb Engineering root directory, click on the menu tomcate project->update context Definition, the project deployed into Tomcat, success will prompt the operation successful.

Click the Tomcat icon in the menu bar to start Tomcat, and then enter http://localhost:8080/testweb/index.do in the IE Address bar, and we will see the index.jsp page content.



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: info-contact@alibabacloud.com 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.