---
title: "实现页面跳转到前一页!"
author: "DavyLee"
date: "2007-09-08T10:10:46Z"
tags: []
slug: "untitled"
draft: false
lastmod: "2007-09-08T10:10:46Z"
id: 121933
url: "https://davylee.iteye.com/blog/121933"
---

Web开发中经常遇到这样的需求，在某个页面a.htm进行某项操作,由于需要登陆而跳转到login.htm进行登陆，而登陆成功后再跳转回a.htm页,下面就对此问题进行简单的实现(webwork+velocity)。
      首先我们在login.htm上放一个隐藏的表单域，叫url:
<input type="hidden" name="url" value=="$req.getHeader('Referer');">,它的值就代表login.htm的前一页（也就是从哪页跳转过来的），然后在登陆流程的Action类里接收一下url这个变量：

```
private String url;//省略setter和getter
```

最后在xwork.xml中跳转到${url}即可，配置如下：

```

<action name="login" class="Login" method="login">
  <result name="success" type="redirect">
    <param name="location">${url}</param>
  </result>
  <result name="error" type="velocity">
    <param name="location">/error.htm</param>
  </result>
</action>

```