平时使用struts是使用xml配置的,学习使用注解
使用maven的,添加依赖包
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.1.8</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>2.1.8</version>
</dependency>
package com.mkyong.user.action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.ResultPath;
import com.opensymphony.xwork2.ActionSupport;
@Namespace("/User")
@ResultPath(value="/")
@Result(name="success",location="pages/login.jsp")
public class LoginAction extends ActionSupport{
}
给某个函数添加,使用如下操作
@Action(value="Welcome", results={
@Result(name="success",location="pages/welcome_user.jsp")
})
public String login() {
return SUCCESS;
}
例子见下面链接:
http://www.mkyong.com/struts2/struts-2-hello-world-annotation-example/
本文介绍如何在Struts框架中使用注解替代XML配置,并提供了实例代码演示。
404

被折叠的 条评论
为什么被折叠?



