Create the first struts2 Program

Source: Internet
Author: User

Everything starts from the simplest, but what is difficult is how deep it can be.

I have three years of work experience and do not need struts. I have always been familiar with jsf, spring mvc, and struts2. When I start blogging, I want to record what I am interested in. I have observed my changes over the past three years, but I have never thought too much. How long can I stick to it as to how much it can change me, wait and see. I once saw struts2 three years ago and thought about me very young. without the guidance of a famous teacher, I was confused. After three years, I looked at him again, and I felt a lot of trouble in controlling these ponies. People grow up unconsciously.

Hello World of Struts2

Development Environment

1. STS 2.9.1

2. Maven 3.0

3. Tomcat 7.0

Maven POM

Create a maven-archetype-quickstart project in STS.

The configuration of struts2 is very simple. Add this in maven depnedency.

 org.apache.struts struts2-core 2.3.15

Maven lib is like this after the successful deployment.

Please input your username

JSP

Test it with basic jsp

Add taglib of struts2

<% @ Taglib prefix = "s" uri = "/struts-tags" %>

 

Logon. jsp

    please input your username  

 

Welcom. jsp

    mxiao sample of struts 2 

Action

Write a HelloAction to record the user's name and return success.

  .username = "SUCCESS"

Struts. xml

This is the struts configuration file, as shown in. It can identify the action and view used by the user's request pair. The following is the simplest example. This file should be stored in classpath at the end, so it should be placed in resources.

 

The above is the process for creating a basic struts program. The project structure is as follows:

Access URL

Http: /localhost: 9084/Struts2Example/User/Login. 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.