Beginners easy to get started with SSH-struts2 01 environment to build, easy to get started with ssh-struts2

Source: Internet
Author: User

Beginners easy to get started with SSH-struts2 01 environment to build, easy to get started with ssh-struts2

First, SSH is not a framework, but an integration of multiple frameworks (struts + spring + hibernate). It is a popular open-source integration framework for Web applications, it is used to build flexible and scalable multi-layer Web applications.

The systems integrated with the SSH framework are divided into four layers: presentation layer, business logic layer, data persistence layer, and domain Module layer (entity Layer ).

As the overall infrastructure of the system, Struts is responsible for the separation of MVC. In the model section of the Struts framework, it controls service redirection and uses the Hibernate framework to provide support for the persistent layer. As a lightweight IoC container, Spring is responsible for searching, locating, creating, and managing dependencies between objects and objects. On the other hand, it can make Struts and Hibernate work better.

Today, we will first access struts2 in SSH. What is struts2? Simply put, it uses Java Servlet/JSP technology to implement an application framework based on the MVC design pattern of Java EEWeb applications. It is a classic product in the classic MVC design pattern.

If you don't need to talk about it, go to today's topic and set up the struts2 environment. The tool used is eclipse, tomcat8, and struts2 2.3.24.

Step 1: Open eclipse to create a web project.

Step 2: import the jar package of struts2 to lib under the WEB-INF under WebContent in the just-built project. Struts2 jar package can download its own http://struts.apache.org/download.cgi on its official website

 

Step 3: Create a New Pageage in src under Java Resources in the project, named com. action. Create a new class in com. action, called LoginAction.

Step 4: Open LoginAction, inherit the ActionSupport class, and implement the default execute method. a success (enumeration value) is returned in the method. You can select this value and press ctrl to click it, other enumerated values are displayed.

Step 4: Create a struts. xml configuration file under src. The xml file needs to introduce the dtd specification, which can be found in the struts2-core-2.3.24.jar of the Web App Libraries in Libraries at the same level of the src folder. Copy it to struts. xml.

Now you can configure the xml file. However, before that, you may find that there is no prompt during configuration! Then you have to display the prompt first. Of course, you can also enter the prompt manually. The configuration tips are as follows: First, select the window in the top menu bar of eclipse, then preferences, enter catalog directly, then click Add, then select the Catalog Entry on the left, and then start operations on the right. To fill in the Location box path, you have to find your struts2-core-2.3.24.jar jar package, and then decompress it, you will find that there are several extensions named dtd. file, because I use the 2.3 version, so I export the path of the 2.3 file, change the Key type to URI, and then you will put your struts. the dtd specification introduced in the xml configuration file is copied at http://struts.apache.org/dtds/struts-2.3.dtd. click OK. Then you can re-open struts. xml to see the prompt.

 

 

Configure struts. xml. Step.

Note that the name attribute in the <result> node should not be written in uppercase because the LoginAction returns an uppercase value. Note that the name attribute must be written in lowercase!

In the last step, you need to configure the filter in web. xml under the WEB-INF under WebContent in the project.

The <filter-class> org. apache. struts2.dispatcher. ng. filter. StrutsPrepareAndExecuteFilter </filter-class> shortcut key ctrl + shift + t can be used to enter strutsp for search.

Now the struts2 environment has been set up. You can start the service, open Google's browser, and enter localhost: 8080/your project name/your address name. action to try.

 

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.