Struts development steps

Source: Internet
Author: User

Struts development steps

To put it bluntly, this simple struts has been tossing around for a long time, and it took about three days to solve it. Below I will summarize the development steps: (I am using MyEclipse );

1. Create an Exercise3 web Project

2. Configure the web. xml file
Add the following code:

 
  
   struts2
  
  
   org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
  
 
 
  
   struts2
  
  
   /*
  
 
3. Add a class library

Place the jar package for example under WEB-INF/lib



4. Create a class

The Code is as follows:

Package cn. wwh. www. struts;/*** function: ** @ author @ * @ version 1.0 * @ Creation Time: 08:44:26 */public class FirstAction {public String firtstMethod () {System. out. println ("hello word, this my first Struts! "); Return" hello ";}}

5. Create a New View/hello/welcome. jsp file under WebRoot.

The Code of welcome. jsp is as follows:

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>              My JSP 'welcome.jsp' starting page    
  
  
      
  
  
            Hello  Word ! welcome to Struts !This is my first Struts.  


6. Create a struts. xml file under src

The Code is as follows:

  
  
   
    hello" class="cn.wwh.www.struts.FirstAction"method="firtstMethod">
    
     /views/hello/welcome.jsp
    
   
  
7. deploy it in tomcat

Enter http: // localhost: 8080/Exercise3/test/hello. action in the browser.

The address bar is changed because the redirect (redirection) method is used in the configuration file.

Result chart:



Note ):

1. The jar package cannot be imported repeatedly. Otherwise, a jar conflict occurs. Due to various jar packages, this exception occurs when tomcat is started.

2. The access address entered in the browser is incorrect. This address combination is related to the namespace and action name in the struts. xml file.

General access method:

Http: // ip: port/contextPath/namespace/actionName [. action]





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.