一个Struts 框架中只能有一个struts-config.xml配置文件吧?

解决方案 »

  1.   

    1. config web.xml file:
    ///
    <servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        <init-param>
           <param-name>application</param-name>
           <param-value>app</param-value>
        </init-param>
        <init-param>
           <param-name>config</param-name>
           <param-value>/WEB-INF/struts-config.xml</param-value>
        </init-param>
        <init-param>
    ***        <param-name>config/test</param-name>
    ***        <param-value>/WEB-INF/struts-config-test.xml</param-value>
        </init-param>
        <init-param>
           <param-name>debug</param-name>
           <param-value>1</param-value>
        </init-param>
        <init-param>
           <param-name>detail</param-name>
           <param-value>3</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
      </servlet>2. prepare struts-config.xml file
    ///add module name before forward's path attribute.
    <struts-config>
    ... 
    <global-forwards>
    <forward name="toModuleB"
    contextRelative="true"  
    path="/moduleB/index.do" 
    redirect="true"/>   
    ... 
    </global-forwards>  
    ...   
    </struts-config>
    ///
      <action-mappings>
    <!-- Action mapping for profile form -->
    <action path="/login" 
    type="com.ncu.test.LoginAction"  
    name="loginForm"     
    scope="request"      
    input="tile.userLogin"
    validate="true">     
    *** <forward name="success" contextRelative="true" path="/moduleA/login.do"/> 
    </action> 
      </action-mappings>
      
      //if you want to return to default configuration,
       forward name="success" contextRelative="true" path="/login.do"/>
      
      //otherwise, you can use SwitchAction
      //A standard Action that switches to a new module and then 
       forwards control to a URI (specified in a number of possible ways) within the new module.
      
      ...
        <action-mappings> 
    <action path="/toModule"
    type="org.apache.struts.actions.SwitchAction"/>  
    ...    
        </action-mappings>  
        ...

    3. You can validate html form data in server-side with dynavalidatorform or actionform's execute method.
    But you can choose Client-side check in your jsp pages, if browser does't support, it will use Server-side
    validator.

    How to set up?
    ////
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <table bgcolor="#9AFF9A" cellspacing="0" cellpadding="10" border="1" width="100%">
    <tr>
    <td> 
    <table cellspacing="0" cellpadding="0" border="0" width="100%"> 
    <tr bgcolor="#696969"> 
    <td align="center">     
    <font color="#FFFFFF">Panel 3: Profile</font>  
    </td>
    </tr> 
    <tr>  
    <td><br> 
    <html:errors/>  
    ***** <html:form action="/login.do" focus="username"  onsubmit="return validateLoginForm(this);">  
    <html:hidden property="actionClass"/>   
    <center>      
    <table>      
    <tr>        
    <td>UserName:</td>   
    <td><html:text property="username" size="20"/></td> 
    </tr> 
    <tr>  
    <td>Password:</td>   
    <td><html:password property="password" size="20"/></td>    
    </tr>  
    <tr>  
    <td colspan=2><html:submit property="submitProperty" value="Submit"/></td>     
    </table>   
    </center>  
    </html:form> 
    ***** <html:javascript formName="loginForm" dynamicJavascript="true" staticJavascript="false"/>  
    ***** <script language="Javascript1.1" src="staticJavascript.jsp"></script>  
    </td> 
    </tr> 
    </table>
    </td>
    </tr>
    </table>
      

  2.   

    配置global.properties.这个东西我做过。有问题请发信[email protected]
      

  3.   

    修改WEB.XML <init-param>
    <param-name>config</param-name>
    <param-value>/WEB-INF/struts-config.xml,
                          /WEB-INF/struts-config-MODELA.xml,
            </param-value>
    </init-param>
      

  4.   

    上面说的都不错,可有一个提醒,要先确定是 Struts 1.1
      

  5.   

    楼上各位好,我重点想知道的是在jsp页面中应该怎么写调用路径,有谁能说详细一点吗?
      

  6.   

    JSP里面在FORM的ACTION直接调,就可以了:
    ....
    <nested:form action="/Login.do" method="post">
    ...
    </nested:form>
    不用殖民是什么模块!
      

  7.   

    jsp里调用actiong="模块/action.do"
    不过我也刚开始用,比较糊涂...这是在菜单里调用..再在里面的jsp里调用的话,就可以直接action="action.do"了..
    我感觉好像  "模块/action.do"转向的jsp里再调用就不用指明 模块了,可以直接 acitong="action.do" ..
    这只是我的感觉,,具体怎样有待有经验者赐教...
      

  8.   

    从request得到请求的module.
    得到request.getAttribute("javax.servlet.include.servlet_path")
    如果为null使用request的path.
    从上面的得到module的prefix
    ,
    然后寻找module.再servletContext中寻找
    Globals.MODULE_KEY+prefix
    得到module的。可以这样认为
    比如说请求路径是
    http:www.fdf.com.cn/webContext/module/XXX.do
    那么没有在request指定javax.servlet.include.servlet_path的话
    请求的module就是名字为module的module.
      

  9.   

    : zez(思恩 为老婆多挣钱 鹤清风) jsp里调用actiong="模块/action.do"
    不过我也刚开始用,比较糊涂...这是在菜单里调用..再在里面的jsp里调用的话,//里面是什么意思?输入的时候?再被其它调用的时候?
    就可以直接action="action.do"了..
    我感觉好像  "模块/action.do"转向的jsp里再调用就不用指明 模块了,//??
    可以直接 acitong="action.do" ..我也刚开始用没多长时间~~~和2星的牛人讨论学习一下~:)
      

  10.   

    一个项目里面只需要用一个struts-config.xml就可以了。