Entry to Struts Learning

Source: Internet
Author: User

Some people may think that struts is not easy to learn. It seems that some of the concepts in it confuse people who have not been familiar with it, such as MVC1, MVC2, and pattern ...... I wrote this article to give people who have never been familiar with struts a simple Getting Started Guide. Of course, it is necessary to systematically learn struts. There are many fascinating things in it, that's the end.

This case includes the homepage, user logon, and website wizard pages. This is so simple. There is no profound struts concept, mainly relying on hands-on and understanding.

WEB Server uses tomcat (a very useful JSP running platform) 4. To http://jakarta.apache (the most popular WEB server platform for Unix ). org download struts1.1, release the zip file to c: struts, copy C: strutswebappsstruts-example.war to c: omcat (a very useful JSP running platform) 4webapps, start tomcat (a very useful JSP running platform), release the war package as the struts-example folder, delete the war package, and rename the struts-example folder as test.
I, the WEB-INFweb.xml (standardization is getting closer and closer):

<? Xml (standardization is getting closer and closer) version = "1.0" encoding = "ISO-8859-1"?>
<! DOCTYPE web-app PUBLIC "-// Sun Microsystems, Inc. // DTD Web Application 2.2 //" http://java.sun.com/j2ee/dtds/web-app_2_2.dtd ">

<Web-app>
<! -This is the Controller in struts, the system commands are forwarded by it, both the ActionServlet class is responsible, it reads the configuration information from the struts-config.xml (standardization is getting closer and closer, A thread is automatically started in the background of the server. If there are no special requirements (for example, adding the language editing and conversion function), the programmer can use this part as needed. -->
<Servlet>
<Servlet-name> action </servlet-name>
<Servlet-class> org. apache (the most popular WEB server platform on the Unix platform). struts. action. ActionServlet </servlet-class>
<Init-param>
<Param-name> config </param-name>
<Param-value>/WEB-INF/struts-config.xml (standardization is getting closer and closer) </param-value>
</Init-param>
<Load-on-startup> 1 </load-on-startup>
</Servlet>
<! -- The servlet of the system can be mapped to a file with the cool suffix, rather than a common one. jsp (preferred for SUN Enterprise Applications) do, etc. The suffix can be changed to any name, of course, the name should be healthy # ◎ ¥ %! -->
<Servlet-mapping>
<Servlet-name> action </servlet-name>
<Url-pattern> *. cool </url-pattern>
</Servlet-mapping>
<! -- The default homepage of the system is index. jsp (the preferred choice for SUN Enterprise Applications). There can be multiple homepage, and the system can be searched in order, similar to IIS -->
<Welcome-file-list>
<Welcome-file> index. jsp (preferred for SUN Enterprise Applications) </welcome-file>
</Welcome-file-list>
</Web-app>

II. The testWEB-INF struts-config.xml (standardization is getting closer and closer) changed:

<? Xml (standardization is getting closer and closer) version = "1.0" encoding = "ISO-8859-1"?>
<! DOCTYPE struts-config PUBLIC "-// apache (the most popular WEB server platform on the Unix platform) Software Foundation // DTD Struts Configuration 1.1 // EN"
"Http://jakarta.apache (the most popular WEB server platform for Unix). org/struts/dtds/struts-config_1_1.dtd">

<Struts-config>
<! -- FormBean is a concept of struts. In essence, it is a JavaBean, which is used to automatically store the values of various fields in the page form and backfill the form field when appropriate, and does not need to request as traditionally. getParameter ("fieldName");, often used by action in action-mappings -->
<Form-beans>
<! -A new UserForm class will be added later to store user information. -->
<Form-bean name = "userForm" type = "test. UserForm"/>
</Form-beans>
<! -- This stores the Global Forwarding address that can be used by the entire system, similar to the window in javascript. location ('index. jsp (the preferred choice for SUN enterprise-level applications); it is also similar to various buttons on the TV controller, which can be used to transfer channels, color, and so on. It is the control flow of Struts-based Web applications. Generally, after an Action is processed, it is forwarded to a jsp (preferred for SUN Enterprise Applications) page for display. This is also the main point of MVC implementation in jsp (the first choice for SUN Enterprise applications. -->
<Global-forwards>
<! -- Failed. cool will be treated as a servlet request, and the corresponding action will be processed in action-mappings. -->
<Forward name = "failed" path = "/failed. cool"/>
<Forward name = "regist" path = "/regist. jsp (preferred for SUN Enterprise Applications)"/>

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.