重转向保留跳转过来的Referer,路径不会变
1 request.getRequestDispatcher("/eventweb/index.sp?loginId=" + loginId).forward(request, response);
重定向的 第一种方式         

       PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<script>");
out.println("window.open ('" + request.getContextPath() + "/eventweb/declare.sp?loginId=" + loginId + "','_top')");
out.println("</script>");
out.println("</html>")
重定向的 第二种方式,跳转时以post方式提交(如果get会展示携带的参数,不安全)

1   RedirectWithPost redirectWithPost = new RedirectWithPost(response);
String redirectUrl = request.getContextPath() + "/eventweb/declare.sp";
redirectWithPost.setParameter("loginId", loginId);
redirectWithPost.sendByPost(redirectUrl);
/**
* 用POST方式 重定向
*
* @author royFly
*/
public class RedirectWithPost {
Map<String, String> parameter = new HashMap<String, String>();
HttpServletResponse response; public RedirectWithPost(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("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD>");
out.println(" <meta http-equiv=Content-Type content=\"text/html; charset=utf-8\">");
out.println(" <TITLE>loading</TITLE>");
out.println(" <meta http-equiv=\"Content-Type\" content=\"text/html charset=GBK\">\n");
out.println(" </HEAD>");
out.println(" <BODY>");
out.println("<form name=\"submitForm\" action=\"" + url + "\" method=\"post\">");
Iterator<String> it = this.parameter.keySet().iterator();
while (it.hasNext()) {
String key = it.next();
out.println("<input type=\"hidden\" name=\"" + key + "\" value=\"" + this.parameter.get(key) + "\"/>");
}
out.println("</from>");
out.println("<script>window.document.submitForm.submit();</script> ");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
}

重定向的 第三种方式

sendRedirect(request, response, url, true);

重定向和转向的写法,重定向以post方式提交的更多相关文章

  1. Python第十天 print >> f,和fd.write()的区别 stdout的buffer 标准输入 标准输出 从控制台重定向到文件 标准错误 重定向 输出流和输入流 捕获sys.exit()调用 optparse argparse

    Python第十天   print >> f,和fd.write()的区别    stdout的buffer  标准输入 标准输出  从控制台重定向到文件  标准错误   重定向 输出流和 ...

  2. layui 时间插件,change&&done,按照官网写法无效,解决方式!

    摘抄自 hahei2020:https://blog.csdn.net/hahei2020/article/details/79285370 layui 时间插件, 当选择时间或时间发生改变后,按照官 ...

  3. iis里URL重写重定向,http做301重定向https

    上一篇文章写了iis和apache共用80端口,IIS代理转发apache. 因为第一次配置,这中间还是碰到了很多问题.这里记录下来,希望以后能避免错误. 使用Application Request ...

  4. jQuery插件写法总结以及面向对象方式写法总结

    前两个是jQuery插件,后面2个是以对象的形式开发,都类似. 写法一 (function($, window){ // 初始态定义 var _oDialogCollections = {}; // ...

  5. Servlet路径跳转1---使用相对路径和绝对路径,在页面上调用servlet的路径写法(超链接的方式和表单的方式)

    课程1-13   http://www.imooc.com/video/5554 Servlet路径跳转: 绝对路径:放在任何地方都对的路径 相对路径:相对于当前资源的路径 index文件 加上/,表 ...

  6. [转]jQuery插件写法总结以及面向对象方式写法

    本文转自:http://www.xuanfengge.com/jquery-plug-in-written-summary-and-summary-of-writing-object-oriented ...

  7. HttpClient相关

    HTTPClient的主页是http://jakarta.apache.org/commons/httpclient/,你可以在这里得到关于HttpClient更加详细的信息 HttpClient入门 ...

  8. HttpClient,DefaultHttpClient使用详解

    HttpClient:是一个接口 首先需要先创建一个DefaultHttpClient的实例 HttpClient httpClient=new DefaultHttpClient(); 发送GET请 ...

  9. httpclient详细介绍

    1.HttpClient简介 HttpClient 是 Apache Jakarta Common 下的子项目,可以用来提供高效的.最新的.功能丰富的支持 HTTP 协议的客户端编程工具包,并且它支持 ...

随机推荐

  1. JS变量连续赋值

    下面就是这个经典案例: var a = {n: 1}; var b = a; a.x = a = {n: 2}; console.log(a);console.log(b); console.log( ...

  2. ubuntu 解压zip 文件乱码

    用 unzip -O cp936 就可以了, 但是,有些发行版所带的 unzip 没有这个参数,比如 ArchLinux 就需要安装 unzip-iconv. Ubuntu 12.04 里面的 unz ...

  3. css 文字对齐

    // html <div>姓名</div> <div>手机号码</div> <div>账号</div> <div>密 ...

  4. python 文件单行循环读取的坑(一个程序中,文件默认只能按行循环读取一次,即使写到另一个循环里,它也只读取一次)

    本来写了一个程序,想获取a文件中有,但是b文件中没有的行: 想到的方法是:1.一行一行提取a文件中数据,然后用a文件中的每一行与b文件中的每一行比较, 2.如果找到相同行就继续查找a中的下一行,如果找 ...

  5. pspice介绍1(转载)

    PSpice的主要功能及特点: OrCAD软件的主要组成包括:OrCAD/Capture CIS.OrCAD/Layout Plus.OrCAD/Express及OrCAD/PSpice.它们分别是: ...

  6. pandas.DataFrame.sample

    DataFrame.sample(n=None, frac=None, replace=False, weights=None, random_state=None, axis=None)[sourc ...

  7. Java programming language does not use call by reference for objects!

    Instead, object references are passed by value! A method cannot modify a parameter of a primitive ty ...

  8. Zabbix微信报警脚本及写触发记录

    一.Zabbix微信报警 默认路径:/usr/lib/zabbix/scripts/weixin.py #!/usr/bin/python # -*- coding: utf-8 -*- import ...

  9. app、web其他测试点

  10. luogu P3768 简单的数学题 杜教筛 + 欧拉反演 + 逆元

    求 $\sum_{i=1}^{n}\sum_{j=1}^{n}ijgcd(i,j)$   考虑欧拉反演: $\sum_{d|n}\varphi(d)=n$   $\Rightarrow \sum_{i ...