ray8837008的专栏

【JAVA】 那点事

【跳转提示】那点事

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;
    }
}

阅读更多
文章标签: null string class
上一篇【博客开张】那点事
下一篇【粗心】那点事
想对作者说点什么? 我来说一句

软件秘笈:设计模式那点事 下载

2016年12月03日 91.03MB 下载

Java程序员上班那点

2009年12月08日 6.03MB 下载

没有更多推荐了,返回首页

关闭
关闭