1. Download required resources 1. Download the JDK 5.0. 2. Download Tomcat 5.5.9 3. Download sysdeo eclipse Tomcat launcher 3.in 3.1beta 4. Install eclipse 3.1ProgramDownload 5. Download the GEF 3.1 Installer (GEF Introduction: http://www.blogjava.net/reloadcn/archive/2005/08/12/GEF1.html) : Http://www.eclipse.org/downloads/download.php? File =/tools/GEF/downloads/drops/R-3.1-200507071758/GEF-ALL-3.1.zip Here we download gef-all-3.1.zip 6. Download the eclipse HTML editor 1.6.7 Installer : Https://sourceforge.jp/projects/amateras/files? Amp; release_id = 16537 Download tk.eclipse.plugin.htmleditor_1.6.7.zip. 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 JDK installation configurations on the Internet.Article. 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 eclipse-sdk-3.1-win32.zip installation package, and cut the eclipse folder to the directory you want to place. Here we 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 tomcatpluginv31beta.zip 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 gef-all-3.1.zip 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. 8. 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> <Head> <Meta http-equiv = "Content-Type" Content = "text/html; Charset = gb2312 "/> <Title> </title> </Head> <Body> <Form name = "form1" method = "Post" Action = "/testweb/logincheck. Do"> <Table width = "300" border = "0" Cellspacing = "0" cellpadding = "0"> <Tr align = "center"> <TD colspan = "2"> User Logon Information </TD> </Tr> <Tr> <TD> User Name </TD> <TD> <Input name = "username" Type = "text" id = "username" Size = "12"> User </TD> </Tr> <Tr> <TD> User Password </TD> <TD> <Input name = "password" Type = "text" id = "password" Size = "12"> 123456 </TD> </Tr> <Tr align = "center"> <TD colspan = "2"> <Input Type = "Submit" name = "Submit" Value = "Submit"> </TD> </Tr> </Table> </Form> </Body> </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 com. Is. form; 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. 7. Install the eclipse HTML editor plug-in Decompress the tk.eclipse.plugin.htmleditor_1.6.7.zip 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 tk.eclipse.plugin.struts_1.1.7.zip 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 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 (Actionmapping mapping, Actionform form, Httpservletrequest request, Httpservletresponse response) Throws exception {
// This line is here for when Input page is upload-utf8.jsp,
// It sets the correct character Encoding 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 ");
}
} } 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> <Head> <Meta http-equiv = "Content-Type" Content = "text/html; Charset = GBK "/> <Title> </title> </Head> <Body> <% String type = request. getparameter ("type "); If (type! = NULL & type. Equals ("true ")){ Out. Print ("Welcome! ");
} Else { Out. Print ("sorry, the user name or password you entered is incorrect! "); } %> </Body> </Html> |
8. Add configuration in Struts-config.xml Add the configuration of formbean and add it to the label:
<Form-bean Name = "loginform" Type = "com. Is. Form. loginform"/> |
Add the JSP ing between JSP files and tags:
<Action Path = "/Index" Forward = "/index. jsp"/> <Action Path = "/welcome" Forward = "/welcome. jsp"/> |
Add the action ing between the action file and the tag:
Path = "/logincheck" Type = "com. Is. Action. loginaction" 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" 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 = "definitions-config" Value = "/WEB-INF/tiles-defs.xml"/> <Set-Property = "moduleaware" value = "true"/> </Plug-in> <Plug-in classname = "Org. Apache. Struts. validator. validatorplugin"> <Set-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. |