1. 程式人生 > >Struts2中action用註解的方式配置

Struts2中action用註解的方式配置

1、在struts.xml中加入下列語句:

<!-- 將action交給spring管理 -->
    <constant name="struts.objectFactory" value="spring" />

2、在Action.java檔案中配置如下:
@ParentPackage("default")
@Namespace("/")
@Component("personalCenterAction")
public class PersonalCenterAction extends com.opensymphony.xwork2.ActionSupport {
    @Action(value = "login",results = {@Result(name = "success",location = "/ok.jsp"),
			               @Result(name = "error",location = "/error.jsp")})
	public String login() {
                return SUCCESS;
         }
}