struts2默认action

struts2的默认action,当其它action都不能匹配时,将用默认的action进行处理。
默认action配置在默认命名空间里。
下面是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.custom.i18n.resources" value="mess"></constant>
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
<package name="struts2" extends="struts-default">
	<default-action-ref name="mo"></default-action-ref>
	<global-results>
		<result name="login">/login.jsp</result>
		<result name="error">/error.jsp</result>
	</global-results>
	<action name="mo" class="com.randy.com.DefaultAction">
		<result name="success">/welcome.jsp</result>
	</action>
	<action name="login" class="com.randy.com.LoginAction">
		<result name="success">/welcome.jsp</result>
	</action>
</package> 
</struts> 

默认的action类:

package com.randy.com;

import com.opensymphony.xwork2.ActionSupport;

public class DefaultAction extends ActionSupport {
	
	private static final long serialVersionUID = 2377192390092411385L;

	public String execute() {
		return ERROR;
	}

}


   交流群:132607763 若满了,请加:251207741

你可能感兴趣的:(struts2,默认action)