Provide a basic Struts+spring+mybatis framework for beginners (mainly to achieve login registration): Configure struts Chapter

Source: Internet
Author: User

---restore content starts---

Write in front:

Before starting to build this framework, for the Java framework: Struts+spring+mybatis completely without any concept, the application of eclipse is not a particularly familiar, but used before, the unfamiliar to eclipse also let me go a little detour. After nearly three weeks of groping or in a cattle man's guidance to complete, ashamed ah ... But in the end, I understood. At that time, I Baidu a variety of Daniel's blog, but because I was too poor foundation, some Daniel's blog are on a certain basis with, and some also use the latest annotations, these let me this beginner to see the confused, can not deny my final build success Baidu's various blogs helped me a lot, but there is a problem, The integration of spring +mybatis has been a headache for me, and online blogs have not met my situation. First I do not need to annotate, secondly I want to build a web version of the framework is to use JSP page to verify the framework. Many are not based on the web version, are directly implemented with a main function.

For this I am here for all beginners like me to provide a general example, for reference only.

Build-based platforms:

Eclipse

The three versions of the framework were:

Struts-2.3.20-all,

Spring-framework-4.0.6.release-dist,

mybatis-3.2.8

These are all available on the official website.

The frame is to be built one step at a

First step: Implant the Struts framework on the Eclipse platform

1. Create a dynamic Web project named SSM on the Eclipse platform

2. Copy the package used to configure struts in the Struts-2.3.20-all\lib to the Lib in the project Ssm\ Web-inf

The package used is as follows:

3. After importing the package simply put struts into the project, and there is no real implementation of the integration of the project and struts, to achieve convergence also need to configure a two configuration files: Web.xml,struts.xml

(1) Why is Web. xml configured?

When you start a Web project, the Web container goes to read its configuration file, XML,

Here, Web. Xml mainly defines the filter and the content to be filtered, as follows:

/*: Indicates that all URLs are to be filtered

(2) Why configure Struts.xml?

Use struts to find the logical class to execute, and to handle the return results of the logical class execution, so that the logical layer can be managed uniformly. (At present it is so understood, and a little superficial!) )

<struts>

<package name= "struts2" extends= "Struts-default" >

<action name= "Login" method= "execute" class= "Loginaction" >

<result name= "SUCCESS" >index.jsp</result>

<result name= "LOGIN" >login.jsp</result>

</action>

</package>

</struts>

Watch out! Struts.xml to be placed in SRC.

4. Set up test jump page for test

Create a test login page login.jsp,index.jsp

<body>

<s:form name= "LoginForm" action= "Login" >

<s:textfield name= "username" label= "username" ></s:textfield>

<s:textfield name= "password" label= "password" ></s:textfield>

<s:submit value= "Submit"/>

</s:form>

</body>

Here the tag needs to be introduced <% @taglib uri= "/struts-tags" prefix= "s"%>

Watch out! the value of the action of form form is the same as the value of the Name property in Struts's action in Struts.xml, so that the form can be processed by struts when it is submitted, thus achieving the fusion of struts.

Watch out! <s:textfield name= "username" label= "user name" ></s:textfield> the property value in name corresponds to the attribute Loginaciton in the logical method username, Password, can not write, if the logical method Loginaciton in the properties Username,password, then the corresponding <s:textfield name= "UserName" label= "User name" ></S: The property value of name in Textfield>.

5. The logical method of establishing a login under src Loginaction.java

Watch out! Property Username,password Get method, set method to use the automatic generation of that, not casually write, casually write, there will be a get the property of the problem.

The Strtus framework is now complete.

Summary: Build the framework, one is to import the package that represents the framework, and the other is to configure the. xml file to achieve a true integration of the project and the framework.

Suggestion: It's best to start with a general understanding of the working mechanism of Struts,spring,mybatis three frameworks

Problems encountered during configuration: no items found

Resolution: 1. Later found that the JSP page misplaced the place, should be placed in the WebContent directory, can not be placed under the Web-inf

2. In Web. XML, configure the default welcome interface. If you do not configure the general default is to skip to index.jsp, of course, if the project exists index.jsp this file, if you want it to jump to login.jsp will be configured to login.jsp.

---restore content ends---

Provide a basic Struts+spring+mybatis framework for beginners (mainly to achieve login registration): Configure struts Chapter

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.