Follow the previous one struts2 After the construction of the framework , The bug is learning again struts2 Knowledge of core configuration files, etc , Now upload your notes ~

Struts2 Core profile for

1、 Core profile content preview

First , Know that struts2 The name of the core configuration file in the framework is struts.xml, The location that exists at the time of creation is the project's src Under the document , As shown in the figure below :
 The location of existence and its name

secondly ,struts.xml The contents of the file are shown in the figure below ( That's the bottom line struts2 Content in the core configuration file of ):
 The core configuration file is about

<?xml version="1.0" encoding="UTF-8"?>
	"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
   <package name="test" namespace="/test" extends="struts-default">
   <action name="TestAction" class="" method="StrutsTest">
      <result name="success">/Test.jsp</result>
   <include file="com/java/B_dynamic/struts.xml"></include>

2、 Basic tag Introduction

Interpret according to the content preview of the core configuration file ~

2.1 struts

This tag is the root tag , It's a sign function , Other things don't help much , No more introduction ;

2.2 package

package, seeing the name of a thing one thinks of its function , Package label , It is used to store... Involved in the same business Action Class configuration label ;
A root tag struts You can store multiple package label ;
One package You can configure multiple Action Configuration information ;

<package name=" " namespace=" " extends=" ">

package Properties of & Property value

  • name: to package Bao Qiming , It's a random name , As long as there is no repetition in the core configuration file , The value of this property is only used to identify , It's easy for developers to distinguish , In the system application, it will not be called and used , Code writing style :name="test";

  • namespace: to Action Define a namespace in the access path of , Code writing style :namespace="/test";
     Namespace name

  • extends: Inherit struts2 Properties of the built-in configuration file , Its attribute value is struts2 Built in profile name “struts-default”, This file is in the folder shown below , This must be configured like this , Code writing style :extends="struts-default"
    “struts-default” File location :
    struts-default File location
    stay struts-default There is this one in the file abstract attribute , This property means whether the package is abstract , Identifying attributes , Its attribute value is true Indicates that the package cannot run independently , Specifically inherited ;

2.3 action

action The function of tags is to configure action Class , Receiving operations are performed in this tag 、 Match the corresponding... For the operation action And methods , Equivalent to express transfer station , Receiving express delivery and further screening and positioning for the destination of express delivery ;

<action name=" " class=" " method=" ">

action Properties of & Property value

  • name: To determine the action The name of the resource accessed , The value of this property is usually what the operation calls action The name of the class , for example :name="TestAction";

  • class: Set this action The complete class name of the class , from src The first folder in the file directory goes directly to this method , for example :class="";

  • method: Specifies that this action Which method of class , for example :method="StrutsTest";

2.4 result

result The function of the tag is to configure the corresponding result for the return value , It's right action What should be the response of the result returned after the method run in , Is redirection 、 Forward to a page or pass the value of an expression back to the configuration ;

<result name="success">...</result>

result Properties of & Property value

  • name: The return value of the configuration method after running , Its property value is the result value returned , It's usually success;
  • type: Decide which result processing method to call , The general default processing method is forwarding ( The property value is dispatcher), There are also redirections 、 Forwarding to action、 Redirect to action And so on , These will be learned later ;
  • Tagging body : Set the jump to that in the tab jsp Just fill in the page jsp The name of the page , Don't forget to add a “/”, Don't forget !!!;

Code writing style :<result name="success">/Test.jsp</result>

The summarized code is the overall code content in the preview above ;

pass: The knowledge in this chapter is very important to struts2 The basic tags are introduced , The next chapter will focus on struts2 Record the constant settings of ~~~

《 End of this chapter 》