功能:

点击login , redirect 到hello.jsp 显示 "hello"

点击redirect, redirect 到 error.jsp 显示 "error"

1.创建Struts2 工程

2.web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

3.index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<s:a action="login">login</s:a><br/>
<s:a action="login!redirect.action">redirect</s:a> <!--此处有bug-->
</body>
</html>

4.LoginAction.java

package com.action;
import com.opensymphony.xwork2.ActionSupport; public class LoginAction extends ActionSupport {
private static final long serialVersionUID=1L;
public String execute() throws Exception{
return SUCCESS;
}
public String redirect() throws Exception{
return ERROR;
}
}

5.UserAction.java

package com.action;
import com.opensymphony.xwork2.ActionSupport; public class UserAction extends ActionSupport {
private static final long serialVersionUID=1L;
public String execute() throws Exception{
return SUCCESS;
}
}

6.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="default" extends="struts-default">
<action name="login" class="com.action.LoginAction">
<result type="redirectAction">
<param name="actionName">userLogin</param>
<param name="namespace">/user</param>
</result>
<result name="error" type="redirectAction">error</result> <!--此处的name为LoginAction.redirect传过来的值ERROR-->
</action>
<action name="error">
<result>/error.jsp</result>
</action>
</package>
<package name="user" extends="struts-default" namespace="/user">
<action name="userLogin" class="com.action.UserAction">
<result>
/hello.jsp
</result>
</action>
</package>
</struts>

7.error.jsp & hello.jsp

<body>
<center>
<h2>error</h2>
</center>
</body> <body>
<center>
<h2>hello</h2>
</center>
</body>

redirect-action的更多相关文章

  1. Grails的redirect无法跳转时的一个可能原因

    由于controller的命名一般首字母大写,如Login 此时如 class LoginController { def index = { redirect(action:Login, param ...

  2. ThinkPHP第十六天(redirect、join、视图模型)

    1.redirect /** * Action跳转(URL重定向) 支持指定模块和延时跳转 * access protected * @param string $url 跳转的URL表达式 * @p ...

  3. 两个action之间进行跳转

    名字 说明 Chain 用来处理Action链 Dispatcher 用来转向页面,通常处理JSP FreeMarker 处理FreeMarker模板 HttpHeader 用来控制特殊的Http行为 ...

  4. Laravel5:重定向 redirect 函数的详细使用

    Laravel5 中新增了一个函数 redirect() 来代替 Laravel4 中 Redirect::to() 来进行重定向操作.函数 redirect() 可以将用户重定向到不同的页面或动作, ...

  5. 配置文件Struts.xml 中type属性 redirect,redirectAction,chain的区别

    1.redirect:action处理完后重定向到一个视图资源(如:jsp页面),请求参数全部丢失,action处理结果也全部丢失.  2.redirectAction:action处理完后重定向到一 ...

  6. Struts2的使用注解配置Action(零配置)

    1.首先引入struts2注解的jar包:struts2-convention-plugin.jar ------------------------------第一种方式-------------- ...

  7. 菜鸟学Struts2——Results

    在对Struts2的Action学习之后,对Struts2的Result进行学习.主要对Struts2文档Guides中的Results分支进行学习,如下图: 1.Result Types(Resul ...

  8. php单点登录之模拟淘宝天猫同步登录

    说到单点登录大家都很了解,一个站点登录其他域会自动登录. 单点登录SSO(Single Sign On)的方法有很多,比如:p3p.共享session.共享cookice.第三方OAuth认证. 这里 ...

  9. [PHP] - Laravel - 用户登陆中间件

    前言 Laravel 4中,可以使用Route::filter,而在Laravel 5中,没有了filter.php文件,官方建议使用中间件做. 下面是用户登陆的测试例子,涉及到的一些方法和使用,先参 ...

  10. [PHP] - Laravel - 列表、新增、修改、删除例子

    前言 Laravel默认是自带了CURD的功能,使用路由的Route::resource可以做到. 但真正的项目中,这往往不是我们所需要的.因为一个项目会有比较复杂的计算.验证等功能. 下面是对项目中 ...

随机推荐

  1. WIN7操作平台获取管理员权限批处理

    在WIN7操作平台打开某些文件,如果需要管理员权限才能打开.通过下面的操作就可以获取管理员权限 创建批处理register文件.文件内容为,文件后缀名为.reg.然后双击该文件.打开需要访问的文件,如 ...

  2. Dede推荐文章与热点文章不显示?

    )先看看,id 文档ID,content 标签最终内容(修改此变量后必须更新系统缓存)是不是填写的id: 进入后台->系统->基本参数设置->性能选项->id 文档ID,con ...

  3. 高反差保留滤镜学习OpenCV:滤镜系列(11)——高反差保留

    这几周笔者几篇文章介绍了改高反差保留滤镜的文章. 关联文章的地址 高反差保留就是高通滤波 r=(pix[x,y]-avg(R))/128 pix[x,y]*r+128*(1-r) #include & ...

  4. ehcache.xml配置参数

    <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLoc ...

  5. 如何实现自己的ClassLoader

    摘自深入分析java web技术内幕

  6. 按自己的想法去理解事件和泛型(C#)

    上一篇那些年困扰我们的委托(C#)讲了委托,这一篇自然就轮到事件了. 不喜欢官方的表达方式,喜欢按照自己的想法去理解一些抽象的东西. 事件 考虑到委托使用的一些缺陷,就有了事件.委托是不安全的,打个比 ...

  7. 【转】关于MySQL函数GROUP_CONCAT的使用

    GROUP_CONCAT()是MySQL数据库提供的一个函数,通常跟GROUP BY一起用,具体可参考MySQL官方文挡:http://dev.mysql.com/doc/refman/5.0/en/ ...

  8. public static void speckOnWin7(string text),在win7中读文字

    public static void speckOnWin7(string text) {    //洪丰写的,转载请注明 try { string lsSource = ""; ...

  9. 负载均衡,最理想使用 redis实现session共享

    负载均衡在多台php服务器负载均衡的情况下,第一秒请求是a服务器,第二秒请求是b服务器, session必须放在一个公共的服务器,最理想是使用 redis实现session共享.内存的速度比磁盘访问快 ...

  10. C# 匿名方法和拉姆达表达式

    有时候,我们需要封装一组数据,只有数据,没有方法,并且只用于当前程序,不需要在项目间重用,这时候,如果是传统的使用类来封装的话,大概会是下面这种样子: internal class SomeData ...