Response重定向实现参数隐藏

最近在弄一个SSH项目,前期已经做好了,现在的需求是进行单点登陆实现,涉及到重定向跳转(带有参数那种)情况,但是不能在地址栏上出现参数的信息,需要进行参数的隐藏跳转。由于时间比较急,本人没来得及开发一个小工具,这次用的别人以前写好的工具类进行参数隐藏。放在这里好让自己积累一些工具类,也方便大家参考!好了,直接上代码:

package com.example.Utils;

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 parameter=new HashMap();
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("
");
Iterator it=this.parameter.keySet().iterator();
while(it.hasNext())
{
String key=it.next();
out.println("");
}
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);//进行跳转

转载于:https://www.cnblogs.com/eagle-lin/p/9866481.html

你可能感兴趣的:(Response重定向实现参数隐藏)