Response重定向实现参数隐藏

最近在弄一个SSH项目,前期已经做好了,现在的需求是进行单点登陆实现,涉及到重定向跳转(带有参数那种)情况,但是不能在地址栏上出现参数的信息,需要进行参数的隐藏跳转。仅供大家参考学习!好了,直接上代码:

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class HttpClientPostFs {
    Map<String, String> parameter=new HashMap<String, String>();
    HttpServletResponse response;

    public HttpClientPostFs()
    {
    }
    public HttpClientPostFs(HttpServletResponse response)
    {
        this.response=response;
    }
    public void setParameter(String key, String value)
    {
        this.parameter.put(key, value);
    }
    public void sendByPost(String url) throws IOException
    {
        this.response.setContentType("text/html");
        PrintWriter out = this.response.getWriter();
        out.println("");
        out.println("");
        out.println(" sender");
        out.println(" ");
        out.println("
+url+"\" method=\"post\">"); Iterator<String> it=this.parameter.keySet().iterator(); while(it.hasNext()) { String key=it.next(); out.println("+key+"\" value=\""+this.parameter.get(key)+"\"/>"); } out.println(""); out.println(" "); out.println(" "); out.println(""); out.flush(); out.close(); } }

上面的是一个工具类的所有内容,下面是调用实现参数隐藏跳转代码展示:

HttpClientPostFs http = new HttpClientPostFs(ServletActionContext.getResponse());
http.setParameter("usercode", "123456");//将参数封装到这个里面,以键值对的形式存在
http.setParameter("password", "123456");
http.sendByPost(url);//进行跳转

你可能感兴趣的:(java,http,java,http)