在struts-default.xml
<result-types>
<!--配置Action连接结果-->
<result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>
<!--配置默认连接结果-->
<result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>
<!--配置freemarker结果类型-->
<result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"/>
<!--配置http请求的类型-->
<result-type name="httpheader" class="org.apache.struts2.dispatcher.HttpHeaderResult"/>
<!--配置重定向结果类型-->
<result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/>
<!--配置重定向action结果类型-->
<result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
<!--配置stream结果类型-->
<result-type name="stream" class="org.apache.struts2.dispatcher.StreamResult"/>
<!--配置velocityResult结果类型-->
<result-type name="velocity" class="org.apache.struts2.dispatcher.VelocityResult"/>
<result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/>
<result-type name="plainText" class="org.apache.struts2.dispatcher.PlainTextResult" />
<!-- Deprecated name form scheduled for removal in Struts 2.1.0. The camelCase versions are preferred. See ww-1707 -->
<result-type name="redirect-action" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
<result-type name="plaintext" class="org.apache.struts2.dispatcher.PlainTextResult" />
</result-types>
例子
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="test" extends="struts-default">
<action name="reg" class="com.struts2.HelloWorld">
<result name="success" type="chain">index</result>
<result name="ERROR" type="chain">
<param name="actionName">reg</param>
</result>
<result name="input" type="chain">
<param name="actionName">reg</param>
</result>
</action>
<action name="index" class="com.struts2.HelloWorld" method="goIndex">
<result name="success">
<param name="location">/index.jsp</param>
</result>
</action>
</package>
</struts>
action
package com.struts2;
import java.util.Date;
import java.util.Map;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorld extends ActionSupport{
/**
*
*/
private static final long serialVersionUID = 1L;
private Date date2;
private String msg;
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public Date getDate2() {
return date2;
}
public void setDate2(Date date2) {
this.date2 = date2;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
private String username;
private int age;
@SuppressWarnings("unchecked")
public String goIndex(){
// Map<String,String> map=null;
// if(this.getUsername().equals(""))
// return ERROR;
// else {
// map=ActionContext.getContext().getSession();
// map.put("username", this.getUsername());
// System.out.println ("姓名"+getUsername()+"\t 年龄:"+this.getAge()+"\t注册日期"+this.getDate2());
// return SUCCESS;
// }
Map<String,String> map=null;
map=ActionContext.getContext().getSession();
map.put("username", this.getUsername());
System.out.println ("姓名"+getUsername()+"\t 年龄:"+this.getAge()+"\t注册日期"+this.getDate2());
return SUCCESS;
}
@Override
public void validate() {
if(username.length()>10){
this.addFieldError("username", "用户名太长了");
}
if(username.equals("")){
this.addFieldError("username", "用户名不能为空");
}
if(age<0||age>150){
this.addFieldError("age", "请输入合法的年龄");
}
}
}
分享到:
相关推荐
关于struts2 Result的配置,有例子
默认包路径包含action,actions,struts,struts2的所有包都会被struts作为含有Action类的路径来搜索。你可以通过设置struts.convention.package.locators属性来修改这个配置。如: <constant name="struts.convention....
struts2 配置文件 result 非常详细 希望能帮到你
Struts2约定优于配置 Action路径到Result页面路径的自动映射
于是就研究使用Struts2的XSLT result方式来做页面显示。 网上相关的内容非常的少,我也研究了好久才玩转的。一开始总是有一些莫名其妙的问题出现,但最后基本上都是和配置相关的比较多。现在这个例子是整个工程项目...
struts2 零配置 使我们项目开发时可以减少很多配置,能够通过一定的规则操作,不需要在配置 result action...等等之类的多于配置
这是一个struts2框架的处理流程的demo,里面有struts2基本的配置和模拟登录的例子,以及struts2前台后后台的数据交互方式的解释,代码中有完整的注释帮助理解struts2的基本流程,同时对jstl和struts2的标签也有一定...
在struts2的返回结果配置中,我们大部分情况使用默认的或者chain或者redirect,其实struts2还有很多其他类型的,今天我们就来看一下都有哪些类型。 打开struts2的源码中struts-default.xml文件,我们能看到如下配置
拦截器:web.xml 配置拦截器<filter> struts2.5的filter-class 与struts2.5以前版本有所不同 <!-- 浏览器访问 http://localhost:8080/MyWeb/helloworld --> --> <?xml version="1.0" encoding=...
NULL 博文链接:https://huangminwen.iteye.com/blog/996219
《Struts 2实战》结合实例介绍了Struts 2框架,主要内容包括Action、Result、Interceptor等框架组件,基于注解的配置选项等新特征,Struts 2插件 FreeMarker,如何从Struts 1和WebWork 2迁移到Struts 2,Ajax标签、...
快速配置Struts2环境 4. 开发一个Struts2简单实例 5. struts.xml文件 三. Struts2深入开发 6. 常用标签配置和使用 7. 常用<result>标签配置和使用 8. 标签 9. Action类的开发 10. 数据类型转换器 ...
11.Result配置详解 15 探讨type类型: 16 Type类型值 16 作用说明 16 对应类 16 chain 16 用来处理Action链 16 com.opensymphony.xwork2.ActionChainResult 16 dispatcher 16 用来转向页面,通常处理JSP 16 org....
Struts2 配置文件result的name属性和type属性
当创建一个对象的时候,它会用Struts2配置文件中的class属性去和Spring配置文件中的id属性进行关联,如果能找到,则由Spring创建,否则由Struts 2框架自身创建,然后由Spring来装配。Spring插件具体有如下几个作用:...
result配置的各种视图转发类型 为Action属性注入值 指定Struts 2处理的请求后缀 Struts 2的处理流程与Action的管理方式 为应用指定多个配置文件 动态方法调用和使用通配符定义action 请求参数接收 自定义...
针对struts2对result配置的各种类型详解
一旦Action执行完毕,ActionInvocation负责根据struts.xml中的配置找到对应的返回结果result。 Struts 2的核心控制器是FilterDispatcher,有3个重要的方法:destroy()、doFilter()和Init(),可以在Struts 2的下载...
该属性指定加载Struts 2配置文件的配置文件管理器.该属性的默认值是org.apache.Struts2.config.DefaultConfiguration, 这是Struts 2默认的配置文件管理器.如果需要实现自己的配置管理器,开发者则可以实现一个实现...
关于MyEclipse对Struts2配置文件较检异常 Invalid result location valueparamete