struts 2プロファイル

14249 ワード

        ,          
      Struts.xml       ,       ,  ,   alt+/     ,    ” http://struts.apache.org/dtds/struts-2.0.dtd”       ,      ,IDE           ,          ,            .
         struts-2.0.dtd    
 MyEclipse       :windowPreferencesMyEclipseFiles and Editors
Xmlxml Catalog          User Specified Entries  Add      Catalog Entry   location   File System                      ,   struts-2.0.dtd key type      URIkey      : http://struts.apache.org/dtds/struts-2.0.dtd ,  OK  .         Struts.xml       ,     Struts   package              .

  ,       HelloWorld  
              , 6 jar ,  struts.xml   src   ,  web.xml  , struts   web   ,       
     :
Chapter1Action
package chapter1.action;

public class Chapter1Action {
private String message;

public String getMessage() {
   return message;
}

public String execute() {
   message = "     Struts2  ";
   return "success";
}
} 

Struts.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.enable.DynamicMethodInvocation" value="false"/> <constant name="struts.devMode" value="false"/> <constant name="struts.i18n.encoding" value="UTF-8"/> <constant name="struts.serve.static.browserCache" value="false"/> <include file="chapter1.xml"/> </struts> chapter1.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="chapter1" namespace="/chapter1" extends="struts-default"> <action name="HelloWorld" class="chapter1.action.Chapter1Action" method="execute"> <result name="success">/WEB-INF/JspPage/chapter1/HelloWorld.jsp</result> </action> </package> </struts> HelloWorld.jsp <%@ page language="java" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>HelloWorld</title> </head> <body> ${message} </body> </html>    :           EL   ,    EL       page,request,session,application           ,                     ,             ?

   : Chapter1Action         ,   Servlet,             ?

Struts2         Action,   Servlet API  ,          , Struts2        ,         HttpServletRequest            ,   Action ,   Action execute          .

Struts.xml     action    <package name="chapter1" namespace="/chapter1" extends="struts-default"> <action name="HelloWorld" class="chapter1.action.Chapter1Action" method="execute"> <result name="success">/WEB-INF/JspPage/chapter1/HelloWorld.jsp</result> </action> </package> Struts2         action,   Servlet web.xml            .     java          ,                action,      ,              action        .

        name  , name         ,     ,          ,           ,  namespace             ,             action      ,   .namespace       ,        ,        ””

          struts-default ,  struts2              , ,            action,                    ,struts-default         Result  ,     ,     struts-default    struts2       ,struts-default   struts2-core-2.xx.jar    struts-defalut.xml   ,struts-default.xml  struts2      ,struts2        struts-default.xml  .

package    abstract=”true”  ,        ,          ,            ,         action  . <action name="HelloWorld" class="chapter1.action.Chapter1Action" method="execute"> <result name="success">/WEB-INF/JspPage/chapter1/HelloWorld.jsp</result> </action> Action   method  ,    method=”execute”,    action      ,         ,      execute     ,  ,         ,      . <result name="success">/WEB-INF/JspPage/chapter1/HelloWorld.jsp</result> result                    ,       .

struts.xml     
             ,   web.xml      ,              ,       ,Struts2        ,         .
           ,          ,             ,            .
            ,        ,      ,         , : <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.enable.DynamicMethodInvocation" value="false"/> <constant name="struts.devMode" value="false"/> <constant name="struts.i18n.encoding" value="UTF-8"/> <constant name="struts.serve.static.browserCache " value="false"/> <include file="chapter1.xml"/> </struts>         <constant name="struts.i18n.encoding" value="UTF-8"/>   Web        ,     HttpServletRequest setCharacterEncoding   <constant name="struts.action.extension" value="do"/>        Struts 2       ,        action,     *.action     Struts 2  。                  ,            (,)  。 <constant name="struts.serve.static.browserCache " value="false"/>              ,    true,      false <constant name="struts.configuration.xml.reload" value="true"/>  struts        ,             ,    false,      true <constant name="struts.devMode" value="true"/>        true,                <constant name="struts.enable.DynamicMethodInvocation" value="false"/>       ,            Servlet   ,      ,   true,     false.

              ,           ,           ,          .

         ,        
struts.serve.static.browserCache                 。          ,                   ,        false。

struts.enable.DynamicMethodInvocation      Struts 2          ,        true。            ,        false。

struts.enable.SlashesInActionNames      Struts 2     Action      ,        false。          Action      ,        true。

struts.tag.altSyntax           Struts 2          ,                  ,         true,        true。

struts.devMode     Struts 2          。        true,             、        。      true flase   ,        false。  ,       ,       true,          ,       false。

struts.i18n.reload         HTTP     ,           。       false。            true       ,                false。

              true,                     ,                ;               false,         ,                         。

struts.ui.theme                ,        xhtml。

struts.ui.templateDir                   ,        template,     template        。

struts.ui.templateSuffix            ,          ftl。        ftl、vm jsp,    FreeMarker、Velocity JSP  。

struts.configuration.xml.reload      struts.xml     ,             。        false。

struts.velocity.configfile     Velocity     velocity.properties     。        velocity.properties。

struts.velocity.contexts     Velocity   Context  ,        Context,   Context       (,)  。

struts.velocity.toolboxlocation     Velocity   toolbox   。

struts.url.http.port     Web         。            ,   Struts 2    URL (  Url  ),      Web       。

struts.url.https.port      struts.url.http.port     ,          Web         。

struts.url.includeParams     Struts 2  URL         。     none、get all     ,        、   GET               。


struts.custom.i18n.resources     Struts 2             ,            ,                (,)  。


struts.dispatcher.parametersWorkaround     Java EE   ,   HttpServlet Request  getParameterMap()  ,           true      。        false。  WebLogic、Orion OC4J   ,          true。

struts.freemarker.manager.classname      Struts 2   FreeMarker   。        org.apache.struts2.views.freemarker.FreemarkerManager,  Struts 2   FreeMarker   。

struts.freemarker.wrapper.altMap      true false     ,    true。          。

struts.xslt.nocache      XSLT Result         。          ,         true;            ,         false。

struts.configuration.files      Struts 2           ,                ,                  (,)  。        struts-default.xml,struts-plugin.xml,struts.xml,      ,         Struts 2      struts.xml   。 


    ,      action     ,             
http://localhost:8080/Struts2/chapter1/HelloWorld
http://localhost:8080/Struts2/chapter1/HelloWorld.action


Action         
        <action name="Login"> <result>/WEB-INF/JspPage/chapter1/Login.jsp</result> </action>     ,         http://localhost:8080/Struts2/chapter1/Login ,           ,       ?

     action  class,   ActionSupport  <action name="Login">     <action name="Login" class="com.opensymphony.xwork2.ActionSupport">      action  method,    action  execute()   <action name="Login">     <action name="Login" class="com.opensymphony.xwork2.ActionSupport" method="execute">       result name  ,    success. <result>     <result name="success">       ActionSupport           ?
               execute    ,  execute    ”success”   ,      ,            . ActionSupport           ,          .

ActionSupport     
struts2          action      struts   struts  ,               action,          com.opensymphony.xwork2.ActionSupport ,       public String execute() throws Exception  。               ,         ,                、             ,         Acion   。 
Struts2       Action   HTTP    ,  ,Action                 ,          getter setter  。

    
   
class="" ActionSupport
method="" execute
name="" “success”

Action           execute  ,        Action        , ActionSupport         ,        ,         ,        Action      ActionSupport            ,   ,          .