信徒疑惑问:struts2零配置,能实现真正没有配置文件吗?
佛说:嗯!
什么个情况?真的?传闻不都是说,不能实现吗?只是一次性配置吗?
如果你这么认为,你就不懂得用struts2的零配置。附件中的项目连struts.xml都没有,照样能用?why?struts2的约定大于配置规则。如果你没有配置,就按约定。
佛说“嗯”的意思是什么?第一:可以不要配置;第二:实际项目中,我们会有一些特定需求,其次,为了项目的需要,想改约定规则,我们还是会加配置,但并不是不能实现零配置。
注意:开发环境是myeclipse10 + jdk1.6
访问路径:http://localhost:8080/struts2-demo/demo!test.action demo-test.jsp
访问路径:http://localhost:8080/struts2-demo/demo!hello.action demo-hello.jsp
访问路径:http://localhost:8080/struts2-demo/demo!sayno.action demo.jsp //看代码注释
DemoAction
package lp.action;
import com.opensymphony.xwork2.ActionSupport;
/**
*
* 用于测试的action
* 零配置测试
* @author liaopin
*
*/
public class DemoAction extends ActionSupport{
private static final long serialVersionUID = 1L;
public String test(){
System.out.println("Login in action");
return "test";
}
public String hello(){
System.out.println("Login in action hello");
return "hello";
}
public String sayno(){
System.out.println("Login in action sayno");
return "nulljsp";//如果没有demo-nulljsp.jsp,默认访问demo.jsp,如果两者都没有,会报找不到对应视图
}
}
pom.xml
<!-- struts2 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.4.1</version>
</dependency>
<!-- Convention 插件默认扫描继承了action类的子类和文件名以Action结尾的文件
默认找的包是struts, struts2, action or action的包 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>2.3.4.1</version>
</dependency>
struts2零配置约定:关于约定的东西,网上一大把,能自己动手就动手找下度娘吧,跟她搞熟!
相关推荐
struts-config.xml struts标准配置文件 struts-config
Struts框架中struts-config.xml文件配置小结
struts.xml和applicationContext.xml、web.xml的配置
struts.xml配置文件详解struts.xml配置文件详解struts.xml配置文件详解
struts.xml文件配置解释,对action配置进行说明
SSH(Struts,Spring,Hibernate)struts.xml文件配置
struts-config.xml配置文件 struts-config.xml配置文件 struts-config.xml配置文件
spring在web.xml中和在struts中的不同配置..pdf
struts2 使用注解现在零配置不需要在使用struts.xml配置文件。 struts2 注解实例。可以直接跑
struts-config.xml配置文件对学struts的人必备的查找资料。
SSH三大框架整合 struts2(使用xml配置)+hibernate(使用xml配置)+spring(使用xml配置),实现分页查询,其他增删该查的接口已经写好。
Struts-config.xml 配置详解.doc Struts-config.xml 配置详解.doc
struts.xml常用配置解析 网上转载
配置MyEclipse Struts2.xml提示方法,更方便的开发Struts2
绝对的好东西 struts2.0中struts.xml配置文件详解
Struts-config.xml配置详解,介绍Struts-config中8个元素配置方法。
·Struts2配置文件介绍 struts.xml action package ·Struts2配置文件介绍 struts.xml action package
struts.xml文件详解.docstruts.xml文件详解.docstruts.xml文件详解.docstruts.xml文件详解.doc
struts2如何配置找到 struts下的提示信息