关闭

【跳转提示】那点事

142人阅读 评论(0) 收藏 举报

package com.ih.util;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForward;

/**
 * @author ray 2011-01-13.
 */
public class MessageForward
{
    /**
     * 跳出提示信息后返回原来的页面.
     *
     * @param response
     * @param message
     * @return
     */
    public static ActionForward alertMessage(HttpServletResponse response, String message)
    {
        response.setContentType("text/html; charset=utf-8");
        PrintWriter out = null;
        try
        {
            out = response.getWriter();
        }
        catch (IOException e)
        {
            e.printStackTrace();
            return null;
        }
        out.flush();
        out.write("<script>alert('" + message + "')</script>");
        out.write("<script>window.history.back(-1)</script>");
        out.close();
        return null;
    }

    /**
     * 跳出提示信息后执行一段代码.
     *
     * @param response
     * @param message
     * @return
     */
    public static ActionForward alertMessage(HttpServletResponse response, String message, String script)
    {
        response.setContentType("text/html; charset=utf-8");
        PrintWriter out = null;
        try
        {
            out = response.getWriter();
        }
        catch (IOException e)
        {
            e.printStackTrace();
            return null;
        }
        out.flush();
        out.write("<script>alert('" + message + "')</script>");
        out.write("<script>" + script + "</script>");
        out.close();
        return null;
    }

    /**
     * 跳出提示信息后转向原来的页面.
     *
     * @param response
     * @param message
     * @return
     */
    public static ActionForward alertMessage(HttpServletRequest request, HttpServletResponse response, String message)
    {
        String referer = request.getHeader("Referer");
        response.setContentType("text/html; charset=utf-8");
        PrintWriter out = null;
        try
        {
            out = response.getWriter();
        }
        catch (IOException e)
        {
            e.printStackTrace();
            return null;
        }
        out.flush();
        out.write("<script>alert('" + message + "')</script>");
        out.write("<script>window.location.href='" + referer + "'</script>");
        out.close();
        return null;
    }
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:4126次
    • 积分:126
    • 等级:
    • 排名:千里之外
    • 原创:10篇
    • 转载:0篇
    • 译文:0篇
    • 评论:3条
    文章分类
    文章存档