Chapter 2 helloworld post under struts 2

Source: Internet
Author: User

Main content of this chapter:

1. Download and install struts 2

2. Create a web application manually

3. Create a struts 2 application manually

4. Implement struts 2 Action

5. Configure struts 2 Action

6. Access httpsession in action

7. output the return value of action in JSP

8. Use the form tag of struts 2

9. Program internationalization preliminary

10. Preliminary data verification

This chapter uses the helloworld application of struts 2 as an example to describe how the struts 2 MVC Framework intercepts user requests, calls the business controller to process user requests, and introduces the ing between action processing results and resources,

The main functions are as follows: the user can enter a logon page, allowing the user to enter the user name and password. If the user's user name and password meet the requirements, the user can enter a welcome page. If the input is incorrect, enter a prompt page. When a user submits a form, this instance will have basic data verification.

Try to introduce JSP Technology

1. download and install the struts 2 Framework

1. Download struts 2.06 (now struts 2.0.11.1)

2,: http://Struts.apache.org/download.cgi#Struts206

3. Download Full Distrubution (full version of struts 2)

4. The structure of the decompressed file is as follows:

(1) Appa

(2) docs

(3) J4

(4) lib

(5) SRC

5. Copy unnecessary class libraries such as *. Jar under the Lib folder to the WEB-INF/lib path.

6. Edit the Web. xml configuration file (Simhei)

<? XML version = "1.0" encoding = "GBK"?>

<Web-app xmlns = "http://java.sun.com/xml/ns/j2ee"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemalocation = "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
Version = "2.4">

<Display-Name> welcome to Tomcat </display-Name>
<Description>
Welcome to Tomcat
</Description>

<! -- Jspc servlet mappings start -->

<Servlet>
<Servlet-Name> org. Apache. jsp. index_jsp </servlet-Name>
<Servlet-class> org. Apache. jsp. index_jsp </servlet-class>
</Servlet>

<Servlet-mapping>
<Servlet-Name> org. Apache. jsp. index_jsp </servlet-Name>
<URL-pattern>/index. jsp </url-pattern>
</Servlet-mapping>

<! -- Jspc servlet mappings end -->

</Web-app>

The following is a JSP page requesting Login

The Code is as follows:

<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<%... @ Page Language = "Java" contenttype = "text/html; charset = GBK" %>
<HTML>
<Head>
<Title> Form Verification </title>
</Head>
<Body>
<Form action = "login. Action" method = "Post">
<Table align = "center">
<Caption> <Tr>
<TD> User name: <input type = "text" name = "username"/> </TD>
</Tr>
<Tr>
<TD> password & nbsp code: <input type = "text" name = "password"/> </TD>
</Tr>
<Tr align = "center">
<TD colspan = "2"> <input type = "Submit" value = "Logon"/>
<Input type = "reset" value = "Refill"/> </TD>
</Tr>
</Table>
</Form>
</Body>
</Html>

Struts 2ServletIt automatically takes effect and forwards the user's request to struts 2 Action

#### Structs 2 Action intercepts all requests suffixed with action by default. Therefore, if you want to submit a form to struts 2 Action for processing, you must set the action attribute to. Action #######

Okay !! Write it first. Read books ....

 

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.