redirect-action
功能:

点击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的更多相关文章
- Grails的redirect无法跳转时的一个可能原因
由于controller的命名一般首字母大写,如Login 此时如 class LoginController { def index = { redirect(action:Login, param ...
- ThinkPHP第十六天(redirect、join、视图模型)
1.redirect /** * Action跳转(URL重定向) 支持指定模块和延时跳转 * access protected * @param string $url 跳转的URL表达式 * @p ...
- 两个action之间进行跳转
名字 说明 Chain 用来处理Action链 Dispatcher 用来转向页面,通常处理JSP FreeMarker 处理FreeMarker模板 HttpHeader 用来控制特殊的Http行为 ...
- Laravel5:重定向 redirect 函数的详细使用
Laravel5 中新增了一个函数 redirect() 来代替 Laravel4 中 Redirect::to() 来进行重定向操作.函数 redirect() 可以将用户重定向到不同的页面或动作, ...
- 配置文件Struts.xml 中type属性 redirect,redirectAction,chain的区别
1.redirect:action处理完后重定向到一个视图资源(如:jsp页面),请求参数全部丢失,action处理结果也全部丢失. 2.redirectAction:action处理完后重定向到一 ...
- Struts2的使用注解配置Action(零配置)
1.首先引入struts2注解的jar包:struts2-convention-plugin.jar ------------------------------第一种方式-------------- ...
- 菜鸟学Struts2——Results
在对Struts2的Action学习之后,对Struts2的Result进行学习.主要对Struts2文档Guides中的Results分支进行学习,如下图: 1.Result Types(Resul ...
- php单点登录之模拟淘宝天猫同步登录
说到单点登录大家都很了解,一个站点登录其他域会自动登录. 单点登录SSO(Single Sign On)的方法有很多,比如:p3p.共享session.共享cookice.第三方OAuth认证. 这里 ...
- [PHP] - Laravel - 用户登陆中间件
前言 Laravel 4中,可以使用Route::filter,而在Laravel 5中,没有了filter.php文件,官方建议使用中间件做. 下面是用户登陆的测试例子,涉及到的一些方法和使用,先参 ...
- [PHP] - Laravel - 列表、新增、修改、删除例子
前言 Laravel默认是自带了CURD的功能,使用路由的Route::resource可以做到. 但真正的项目中,这往往不是我们所需要的.因为一个项目会有比较复杂的计算.验证等功能. 下面是对项目中 ...
随机推荐
- shell脚本兼容linux/unix与windows/cygwin的基础(注意处理好CR, LF, CR/LF 回车 换行的问题)
shell脚本兼容linux/unix与windows/cygwin的基础 :统一文本格式为:unix文本格式,即于LF为换行符(推荐方案) 在notepad上设置:编辑->档案格式转换-> ...
- C++malloc,calloc,realloc,free函数
在进行C/c++编程的时候,需要程序员对内存的了解比较清楚,经常需要操作的内存可分为下面几个类别: 1.堆栈区(stack):由编译器自动分配与释放,存放函数的参数值,局部变量,临时变量等等, ...
- Facebook开源的基于SQL的操作系统检测和监控框架:osquery daemon详解
osqueryd osqueryd(osquery daemon)是可以定期执行SQL查询和记录系统状态改变的驻守程序. osqueryd能够根据配置手机归档查询结果,并产生日志. 同时也可以使用系统 ...
- 从ICassFactory为CLSID为{17BCA6E8-A950-497E-B2F9-AF6AA475916F}的COM组件创建实例失败,原因是出现以下错误:c001f011.(Microsoft.Server.manageDTS
从ICassFactory为CLSID为{17BCA6E8-A950-497E-B2F9-AF6AA475916F}的COM组件创建实例失败,原因是出现以下错误:c001f011.(Microsoft ...
- X86 IO端口和MMIO
X86 IO端口和MMIO I/O作为CPU和外设交流的一个渠道,主要分为两种,一种是Port I/O,一种是MMIO(Memory mapping I/O).前者就是我们常说的I/O端口,它实际上的 ...
- Thymeleaf 笔记
th:each=”aname : ${namelist}” th:if=”${name} == ‘SERVICED’” 页面使用Map集合 <div th:each="osl : ${ ...
- 如何编译Apache Hadoop2.2.0源代码
转自(原文图片已丢失,本文修复图片,重新排版,并更正部分原文错误):http://www.superwu.cn/2013/12/26/913 欢迎和大家交流技术相关问题: 邮箱: jiangxinnj ...
- 虚拟机学习centos服务器版
虚拟机安装下载教程:http://www.cnblogs.com/CyLee/p/5615322.html centos 6.5下载地址:http://www.centoscn.com/CentosS ...
- 修改linux默认ssh 端口
修改ssh的默认端口 1.编辑ssh配置文件: #vi /etc/ssh/ssh_config #vi /etc/ssh/sshd_config ...
- servlet笔记
开发servlet有三种方法: (1) 实现 Servlet接口 (2) 通过继承 GenericServlet (3) 通过继承 HttpServlet get提交和post提交的 ...