Struts2 Annotation的<param-name>actionPackages</param-name>讲解

来源:互联网 发布:象棋软件排名 编辑:程序博客网 时间:2024/06/16 16:25
                                              

Struts2 Annotation配置

 

Struts2 Annotation在官网上叫零配置文件(就是可以没有struts2.xml),通过java annotation注释来代替struts2.xml文件。

 

修改web.xml配置文件:
<param-name>actionPackages</param-name>这是名称是默认的(不可以改的)
要改的是下边的:<param-value>action</param-value> 里的内容是你写的action所在的包路径

struts2会去扫描这个包来找到里面的action
(上面的action代表的就是action在哪个java包中)
比如你在com.lovo.yfx包下建了一个Action的类那么就得写成
<param-value>com.lovo.yfx</param-value>

 

 

就是Struts2 Annotation的jar包在struts2-codebehind-plugin-2.x.x.x.jar的jar包中

 

在action的包里我写一个最简单的类如下:
package action;//这个action就是<param-value></param-value>要写的
import org.apache.struts2.config.Action;
import org.apache.struts2.config.Namespace;
import org.apache.struts2.config.Result;import com.opensymphony.xwork2.ActionSupport;
@Namespace("/action")
@Action(name = "action")
@Result("/login.html")
public class LoginAction extends ActionSupport{    @Override
    public String execute() throws Exception {
        return SUCCESS;
    }
    
}

原创粉丝点击