Java from getting started to giving up: a basic way to access Struts2

Source: Internet
Author: User

What the hell is Struts2?

Citing the introduction of Baidu Encyclopedia:Struts2 is a Web application framework based on the MVC design pattern, essentially equivalent to a servlet, in the MVC design pattern, Struts2 as a controller to establish the data interaction between the model and the view. .

Introduction completed ...

Its core schematic diagram online a lot, I made a simple change here, if there is not enough to explain the place, please correct me. Schematic please look:

All right, we're almost done here, let's talk about something useful. Struts2 How to use it, look at the following steps

1. Create a new Web project (as if it were nonsense)

2. Import the Struts2 jar package

3. Writing the Web. XML configuration

4. Writing Struts.xml Configuration

5. Write the Action class

6. Writing JSP pages

The first two steps are ignored, directly starting with the third step:

3. Introducing Struts2 in Web. XML (actually a filter)

12345678   <filter>    <filter-name>struts2</filter-name>    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>  </filter>  <filter-mapping>    <filter-name>struts2</filter-name>    <url-pattern>/*</url-pattern>  </filter-mapping>

4. Write the Struts.xml configuration (this file is placed in the SRC root directory)

123456 <packagename="default"namespace="/"extends="struts-default">    <!-- 指定Method调用 -->    <actionname="userLogin"class="com.pxy.action.Hello">    <result>/login.jsp</result>    </action></package>

5. Write the action class (put in the com.pxy.action package)

12345678 publicclass Hello extendsActionSupport {    @Override    publicString execute() throwsException {        System.out.println("默认调用的方法!");        returnSUCCESS;    }}

6. Writing JSP pages

12345678 <body>      登录界面<br/>    <formaction=""method="post">        账号:<inputtype="text"name="loginid"/><br/>        密码:<inputtype="password"name="loginpwd"/><br/>        <inputtype="submit"value="登录"/>    </form>  </body>

All the coding is done here, and then we enter the http://localhost:8080/strDemo/userLogin.action in the address bar to try the results. Normal access to the login.jsp page.

I modified the tomcat port to 8888.

Sir, you are satisfied.

If something goes wrong, it must be your posture is not right, get up and go to bed again.

If it is not right, then sleep a little more, wake up must be normal, please believe me ...

Java from getting started to giving up: a basic way to access Struts2

Related Article

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.