重定向和转向的写法,重定向以post方式提交
重转向保留跳转过来的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方式提交的更多相关文章
- Python第十天 print >> f,和fd.write()的区别 stdout的buffer 标准输入 标准输出 从控制台重定向到文件 标准错误 重定向 输出流和输入流 捕获sys.exit()调用 optparse argparse
Python第十天 print >> f,和fd.write()的区别 stdout的buffer 标准输入 标准输出 从控制台重定向到文件 标准错误 重定向 输出流和 ...
- layui 时间插件,change&&done,按照官网写法无效,解决方式!
摘抄自 hahei2020:https://blog.csdn.net/hahei2020/article/details/79285370 layui 时间插件, 当选择时间或时间发生改变后,按照官 ...
- iis里URL重写重定向,http做301重定向https
上一篇文章写了iis和apache共用80端口,IIS代理转发apache. 因为第一次配置,这中间还是碰到了很多问题.这里记录下来,希望以后能避免错误. 使用Application Request ...
- jQuery插件写法总结以及面向对象方式写法总结
前两个是jQuery插件,后面2个是以对象的形式开发,都类似. 写法一 (function($, window){ // 初始态定义 var _oDialogCollections = {}; // ...
- Servlet路径跳转1---使用相对路径和绝对路径,在页面上调用servlet的路径写法(超链接的方式和表单的方式)
课程1-13 http://www.imooc.com/video/5554 Servlet路径跳转: 绝对路径:放在任何地方都对的路径 相对路径:相对于当前资源的路径 index文件 加上/,表 ...
- [转]jQuery插件写法总结以及面向对象方式写法
本文转自:http://www.xuanfengge.com/jquery-plug-in-written-summary-and-summary-of-writing-object-oriented ...
- HttpClient相关
HTTPClient的主页是http://jakarta.apache.org/commons/httpclient/,你可以在这里得到关于HttpClient更加详细的信息 HttpClient入门 ...
- HttpClient,DefaultHttpClient使用详解
HttpClient:是一个接口 首先需要先创建一个DefaultHttpClient的实例 HttpClient httpClient=new DefaultHttpClient(); 发送GET请 ...
- httpclient详细介绍
1.HttpClient简介 HttpClient 是 Apache Jakarta Common 下的子项目,可以用来提供高效的.最新的.功能丰富的支持 HTTP 协议的客户端编程工具包,并且它支持 ...
随机推荐
- python学习第二十六天非固定参数几种情况
python函数参数传递,位置参数,默认参数,关键词参数,最后介绍一个非固定参数,就可以向函数传递一个列表,元组,字典,具体看看用法 1,有一个* 号的参数情况 def goos_stu(id,*us ...
- python 模块和包深度学习理解
python 模块和包 简单说相当于命名空间 1,python 模块 python模块就是一个文件,里面有函数,变量等 import 模块 模块.方法 from 模块 import fu ...
- gulp run 报错 gulp[3192]: src\node_contextify.cc:628: Assertion `args[1]->IsString()' failed.
由于把node升级到了10以上的版本 执行gulp rjs打包文件报错,错误如下: gulp[3192]: src\node_contextify.cc:628: Assertion `args[1] ...
- NGUI的Lebal需注意问题
1,为什么调节字体大小时,字体大小没变化,我们需要调节两个地方,如下图框柱显示 调节font size和size才可以同时控制字体的大小 2,label有时是不支持输入中文,但是支持复制进去,则这时我 ...
- 5.把报表集成到Web应用程序中-生成网页和导出两种方式
转自:https://wenku.baidu.com/view/104156f9770bf78a65295462.html 第四部分,把报表集成到Web应用程序中 用MyEclipse新建一个Web ...
- Spring Boot 项目 Maven 配置
在配置基于Maven的Spring Boot项目的过程中,打包运行出现了一系列错误. 比如: mvn 中没有主清单属性.java.lang.NoClassDefFoundError: org/spri ...
- 01.Linux-CentOS系统网卡名称变动问题
方法一root登陆系统1.删除原来的配置信息[root@localhost ~]# rm -f /etc/sysconfig/network-scripts/ifcfg-eth0[root@local ...
- 前端每日实战:47# 视频演示如何用纯 CSS 创作一个蝴蝶标本展示框
效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/xzgZzQ 可交互视频教程 此视频 ...
- JDBC和驱动类Driver
什么是JDBC? JDBC(Java DataBase Connectivity),是一套面向对象的应用程序接口(API),制定了统一的访问各类关系数据库的标准接口,为各个数据库厂商提供了标准的实现. ...
- List接口和Set接口及其常用实现类概述
一.List接口 List:有序的 collection(也称为序列).此接口的用户可以对列表中每个元素的插入位置进行精确地控制.用户可以根据元素的整数索引(在列表中的位置)访问元素,并搜索列表中的元 ...