重转向保留跳转过来的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. python 实现加法

    https://ac.nowcoder.com/acm/contest/338/G 链接:https://ac.nowcoder.com/acm/contest/338/G来源:牛客网 题目描述 Th ...

  2. spring boot 配置文件优先级

    项目中可能存在多个配置文件,那么优先级定义如下: 1.同一目录,application.properties优先级高于application.yml 2.同一目录,config文件夹下的配置文件高于根 ...

  3. 设置第一个以外的元素样式:not(:first-child),设置最后一个除外的元素样式:not(:last-child)

    代码截图:

  4. 20180209-shutil模块

    下面讲解shutil模块的相关操作: 1.shutil.copyfileobj(fsrc, fdst, length=16*1024) 将fsrc文件内容拷贝到fdst文件中,length是指一次拷贝 ...

  5. H5手机端底部菜单覆盖中间部分内容的解决办法

    一.第一种Js动态计算中间内容的高度. 二.第二种给底部上面写个<div style="底部的高度"></div> 三.第三种给中间部分写一个margin- ...

  6. 六、SQL语句进行多条件查询,并解决参数为空的情况

    一.SQL语句进行多条件查询,并解决参数为空的情况 QueryEntity query; var whereSql = new StringBuilder("Where 1=1") ...

  7. Error- Overloaded method value createDirectStream in error Spark Streaming打包报错

    直接上代码 StreamingExamples.setStreamingLogLevels() val Array(brokers, topics) = args // Create context ...

  8. 逗号导致hive报“SemanticException Error in parsing”错误

    > select p.dt, p.cookie_qunar_global, p.refer_domain, p.kwid, p.query_word, p,traffic_type--, p.p ...

  9. python tkinter开始

    tkinter是python自带的GUI库,所以用起来会比较简单 运行一个什么都没有的窗口 import tkinter window=tkinter.Tk()#窗口类定义 window.mainlo ...

  10. python2和python3的编码encode解码decode函数

    python比较坑的一个点:意义完全变了的两个函数 首先 常用的编码方式有3种,utf-8:  常用的传输和存储格式,Unicode的一种简化 Unicode:包括了所有可能字符的国际统一编码 GBK ...