论坛首页 Java企业应用论坛

Struts2的配置参数解释

浏览 2749 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (1) :: 隐藏帖 (1)
作者 正文
   发表时间:2009-08-09   最后修改:2009-08-09
<?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.objectFactory" value="spring" />
	<include file="struts-default.xml"></include>
	
	<package name="default" extends="struts-default">
		<action name="user_*" method="{1}" class="LoginAction">
			<result name="error">/error.jsp</result>
			<result name="loginsuccess">/ok.jsp</result>
			<result name="registsuccess">/success.jsp</result>
			<result name="logout">/index.jsp</result>
			<result name="register">/admin/users_insert.jsp</result>
			<result name="update">/admin/users_update.jsp</result>
			<!-- 
			<result name="userlist">/admin/users_list.jsp</result> 
			<result name="userlist" type="freemarker">/query.ftl</result>
			-->
			<result name="userlist">/admin/users_list.jsp</result> 
		</action>
	</package>
</struts>


这里的method="{1}"是指什么呢?
   发表时间:2009-08-09  
占位符,与'*'相匹配,就是说如果请求的路径是user_add则method='add',建议去书店找本struts2的书看看
0 请登录后投票
   发表时间:2009-08-09  
http://struts.apache.org/2.1.6/docs/action-configuration.html
Wildcard Method
Many times, a set of action mappings will share a common pattern. For example, all your edit actions might start with the word "edit", and call the edit method on the Action class. The delete actions might use the same pattern, but call the delete method instead.

Rather than code a separate mapping for each action class that uses this pattern, you can write it once as a wildcard mapping.

<action name="*Crud" class="example.Crud" method="{1}">
    ...
Here, a reference to "editCrud" will call the edit method on an instance of the Crud Action class. Likewise, a reference to "deleteCrud" will call the delete method instead.

Another common approach is to postfix the method name and set it off with an exclamation point (aka "bang"), underscore, or other special character.

"action=Crud_input"
"action=Crud_delete"
To use a postfix wildcard, just move the asterisk and add an underscore.

<action name="Crud_*" class="example.Crud" method="{1}">
From the framework's perspective, a wildcard mapping creates a new "virtual" mapping with all the same attributes as a conventional, static mapping. As a result, you can use the expanded wildcard name as the name of validation, type conversion, and message resource files, just as if it were an Action name (which it is!).

Crud_input-validation.xml
Crud_delete-conversion.xml
If Wildcard Method mapping uses a "Unable to render embedded object: File (" in the action name, the Wildcard Method will overlap with another flexible approach to mapping, Dynamic Method Invocation. To use action names that include the ") not found." character, set struts.enable.DynamicMethodInvocation to FALSE in the application configuration. 
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics