action的注解实例

  • action类的注解配置代码

package action;

import org.apache.struts2.config.Namespace;
import org.apache.struts2.config.Result;
import org.apache.struts2.config.Results;
import org.apache.struts2.dispatcher.ServletDispatcherResult;

import com.opensymphony.xwork2.ActionSupport;

@Namespace("/action")
@Result("/success.jsp")
@Results({
	@Result(name="login",value="/login.jsp"),
	@Result(name="error",value="/error.jsp",type=ServletDispatcherResult.class)

})
public class AnnotationAction extends ActionSupport{

	public String execute() throws Exception{
		return SUCCESS;
	}
	public String input() throws Exception{
		return INPUT;
	}
	public String error() throws Exception{
		return ERROR;
	}
}
  • web.xml中配置actionPackages参数

如果actionPackages的参数值有多个包,则包之间需要用“,”隔开。

       



	
        struts2        
        org.apache.struts2.dispatcher.FilterDispatcher
        
   		
   			actionPackages
   			action
   		
    
    
        struts2
        /*
    
  
    index.jsp
  


  • URL请求地址

http://localhost:8080/Demo/action/annotation.action
http://localhost:8080/Demo/action/annotation!input.action
http://localhost:8080/Demo/action/annotation!error.action



你可能感兴趣的:(action的注解实例)