Eclipse development struts Guide

  Abstract: This paper describes the package explorer in the eclipse will be seen in the increase in a lot of struts of the library in the WEB-INF also increased under a lot of struts configuration files.    In this project we have joined the Struts framework. 

  One for the installer 

  1, JDK 5.0 installation program download 

  Download Address: 

  Https: / / jsecom15b.sun.com/ECom/EComActionServlet 
  / DownloadPage: ~: com.sun. 
  Sunit.sdlc.content.DownloadPageInfo; 
  Jsessionid = 502E87C71D77E3BC297C08B35 
  DAC9AD4; jsessionid = 502E87C71D77E3BC297C08B35DAC9AD4 

  Agree with the agreement, can be downloaded 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 5.5.11 alpha version because it is beta, so there may be an element of uncertainty, which is why we here to download the 5.5.9 exe. 

  3, Sysdeo Eclipse Tomcat Launcher plugin 3.1beta edition 

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

  TomcatPluginV31beta.zip here to download. 

  4, eclipse 3.1 installation program download 

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

  It should be corresponding version of the JDT, if you download the Eclipse SDK versions own, and if not, with a download page on after some of the JDT download links, download the corresponding documents will be copied into eclipse respectively installation directory the corresponding documents 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 installer download 

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

  Here we Download: tk.eclipse.plugin.struts_1.1.7.zip. 

  Well, here we all ready for the installation of the package. 

  Second, install and configure the development environment JDK 

  JDK here need only double-click on the exe file installation package, in accordance with tips can be installed.    After the installation is complete, JDK installed under the bin directory folder settings into the path environment variable PATH to.    At the same time, the JRE lib directory of rt.jar packages installed into the environment variable to the classpath. 

  Here we JDK installed on the default installation path C: \ Program Files \ Java \ jdk1.5.0_02 under.    Here is not to say, the Internet can search many JDK installation configuration articles. 

  Third, the installation tomcat server 

  Tomcat need only double-click on the exe file installation packages, and can be installed in accordance with the tips, here we install directory to D: \ Tomcat5.5, the administrator password is set to 12345678. 

  4, installation Eclipse development tools 

  Need only to eclipse-SDK-3.1-win32.zip install decompression, and then inside the eclipse folder shear to the directory to be placed, where we have installed to eclipse the D: \ eclipse directory. 

  Double-click the installation directory eclipse.exe documents, you will start eclipse.    Middle will ask the default working directory, you can according to their default settings, you can also set their own working directory, here set to E: \ workspace directory.    Select Use this as the default and do not ask again options after this start will not be asked to. 

  Eclipse the success of this installation. 

  5, plug-in installed tomcatPlugin 

  Installation is very simple, we have to extract the downloaded installation package tomcatPluginV31beta.zip will extract the com.sysdeo.eclipse.tomcat_3.1.0.beta folder copy to the D: \ eclipse \ plugins directory can be.    We turn off the eclipse has been opened, re-opened, OK, we are now found on the toolbar more than a few Tomcat icon is the tomcat start, stop and restart button.    Eclipse the open window / preferences, we have trees on the left can also be found a tomcat. 

  Click tomcat items, we have chosen the right version 5.x version, and then set tomcat home to the D: \ Tomcat5.5, Contexts directory to D: \ Tomcat5.5 \ conf \ Catalina \ localhost.    Completion of this tomcat plugin installed. 

  6, installation GEF Plugin 

  Similarly, the GEF-ALL-3.1.zip decompress, and then copy decompression after the eclipse directory of the three folders to the D: \ eclipse directory covering all existing folder. 

  Well, this GEF installation is complete. 

  8, creating a test project 

  If you have completed all the above steps can now be restarted eclipse, the newly installed plug-in force, officially developed. 

  1, the use of Sysdeo Tomcat Plugin create tomcat works: 

  File -> new-> others, open new Wizard dialog box, a tree found in java-> tomcat projects, selected, click the next button.    Enter in the projects name textweb, select Use default, click next.    The next Talk to maintain the default settings, click finished.    At this time, we have the package explorer eclipse will be seen in the new project testweb to create complete. 

  2, by adding struts framework 

  File-> new-> others, open new Wizard dialog box, find Amateras-> Struts-> Add Struts Support, select next button click. 

  Keep the default settings, click the Finish button.    Then, in the package explorer eclipse will be seen in the increase in a lot of struts of the library in the WEB-INF also increased under a lot of struts configuration files.    In this project we have joined the Struts framework. 

  3, edit struts-config.xml file 

  In the WEB-INF folder can be found, right-click menu options open with-> Amateras XML Editer can directly edit the xml text, select open with-> struts-config.xml editor in the graphics mode of documents edit. 

  On the right side click on the outline of the struts objects can be added into a new object.    Here, we note here is a more convenient struts-config.xml file editor, we will be behind the development of a simple small procedures. 

  4, a new page index.jsp 

  File-> new-> others, open new Wizard dialog box, find Amateras-> JSP File, click the next button, FileName to index.jsp, click Finish.    Then open index.jsp document for editing, as follows: 

  <% @ Page pageEncoding = "GBK" 
  ContentType = "text / html; 
  Gb2312 charset = "%> 

<head>
  Content = "text / html; 
  Gb2312 charset = "/> 

  </ 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 login information </ td> 
  </ Tr> 
<tr>
  <td> User name </ td> 
<td>
  <Input name = "username" 

type=”text” id=”username”
  Size = "12"> 
  User 
  </ Td> 
  </ Tr> 
<tr>
  <td> User passwords </ 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> 

  5, create data objects form 

  Open File-> new-> package dialog box, enter com.is.form name, and click Finish button.    Package Explorer in the right of the tree to find just the creation package, right-click com.is.form package, the new menu-> others, find Amateras-> struts-> Struts Action Form, click next, in the name in the dialog box LoginForm input column, click Finish button. 

  Edit the contents of LoginForm categories: 

  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 that the two properties were jsp our counterparts in the form of the name of the two input controls, why do so, can look at the struts with the help of documents, I do not detail, also finished form another category attributes, get and set methods can eclipse the source of commands to automatically generate, in the pop-up menu, no detail, to check information on the Internet bar, the use of the eclipse there are many documents. 

  7, plug-in installed Eclipse HTML Editor 

  Decompress tk.eclipse.plugin.htmleditor_1.6.7.zip packets, and then copy plugins directory to D: \ eclipse directory covering the original document folder.    Eclipse HTML Editor plug-in this installation is complete. 

  8, plug-ins installed StrutsIDE 

  Decompress tk.eclipse.plugin.struts_1.1.7.zip packets, and then copy plugins directory to D: \ eclipse directory covering the original document folder. 

  Well, here StrutsIDE plug-in installed. 

  6, objects to create action 

  The same process to create the same form, we are only a com.is.action new package, the same process, opened new wizard, but choose Struts Action, create LoginAction.java type, default value of the election.    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 the 
  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; 

  ) 
  ) 

  Attention here is the direct use of ActionForward to, and you can also provide the blank struts routines struts-blank.war practices in turn, can be compared to the harvest. 

  7, pages created successful login 

  Index.jsp with the creation of the same pages, we create welcome.jsp page, use the default settings.    And edit its content as follows: 

  <% @ Page pageEncoding = "GBK" 
  ContentType = "text / html; 
  GBK charset = "%> 

<head>
  Content = "text / html; 
  GBK charset = "/> 

  </ Head> 
<body>
<%
  String type = request.getParameter ( "type"); 
  If (type! = Null & type.equals ( "true")) ( 
  Out.print ( "welcome to you!"); 

  ) 
  Else ( 
  Out.print ( "Sorry, you enter the user name or password wrong!"); 
  ) 
%>
  </ Body> 

  8, the increase in Struts-config.xml configuration 

  Add formbean configuration, and labelling between Accession: 

  <Form-bean 

name=”loginForm”
  Type = "com.is.form.LoginForm" /> 

  Add jsp document mapping, and labelling between Accession: 

  Path = "/ index" 
  Forward = "/ index.jsp" /> 
  Path = "/ welcome" 
  Forward = "/ welcome.jsp" /> 

  Add action document mapping, and labelling between Accession: 

  Path = "/ logincheck" 
  Type = "com.is.action.LoginAction" 
  Name = "loginForm" 
  Scope = "request" 
  Validate = "true" /> 

  After the revised struts-config.xml form along the following lines: 

  <? Xml version = "1.0"> 
  Struts-config PUBLIC "– 
  / / Apache Software Foundation 
  / / DTD Struts Configuration 1.2 / / EN " 
  "Http://struts.apache.org/dtds 
  / Struts-config_1_2.dtd "> 



<form-beans>
  <Form-bean 

name=”loginForm”
  Type = "com.is.form.LoginForm" /> 
  </ Form-beans> 





  Path = "/ index" 
  Forward = "/ index.jsp" /> 
  Path = "/ welcome" 
  Forward = "/ welcome.jsp" /> 
  Path = "/ logincheck" 
  Type = "com.is.action.LoginAction" 
  Name = "loginForm" 
  Scope = "request" 
  Validate = "true" /> 

  "Org.apache.struts.tiles.TilesRequestProcessor" /> 

  "Org.apache.struts.tiles.TilesPlugin"> 
  Value = "/ WEB-INF/tiles-defs.xml" /> 

  "Org.apache.struts.validator.ValidatorPlugIn"> 
  Value = "/ WEB-INF/validator-rules.xml, 
  / WEB-INF/validation.xml "/> 

  We can run this test procedure. 

  9, testing procedures 

  Right-click testweb project root directory, click on the menu Tomcate project-> update context definition, the project will be deployed into the tomcat, after the success will be prompted to operate successfully. 

  Click on the menu bar icon Tomcat start tomcat, and then enter the address bar in IE http://localhost:8080/testweb/index.do, we will see index.jsp content pages. 

  ↑ Back 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags: ,

Releated Java Articles

Comments

Leave a Reply