当前位置: 首页 > news >正文

form表单

转载地址:http://www.anyrt.com/blog/list/submit.html

转载地址:http://www.cnblogs.com/fish-li/archive/2011/07/17/2108884.html

转载地址:https://blog.csdn.net/u013551462/article/details/52742790

form表单提交方式

无刷新页面提交表单

表单可实现无刷新页面提交,无需页面跳转,如下,通过一个隐藏的iframe实现,form表单的target设置为iframe的name名称,
form提交目标位当前页面iframe则不会刷新页面

<form action="/url.do" method="post" target="targetIfr">
<input type="text" name="name"/>
</form>   
<iframe name="targetIfr" style="display:none"></iframe> 
              

通过type=submit提交

一般表单提交通过type=submit实现,input type="submit",浏览器显示为button按钮,通过点击这个按钮提交表单数据跳转到/url.do

<form action="/url.do" method="post">
   <input type="text" name="name"/>
   <input type="submit" value="提交">
</form>
              

js提交form表单

js事件触发表单提交,通过button、链接等触发事件,js调用submit()方法提交表单数据,jquery通过submit()方法

<form id="form" action="/url.do" method="post">
   <input type="text" name="name"/>
</form>
              

js: document.getElementById("form").submit();
jquery: $("#form").submit();

ajax异步提交表单数据

采用ajax异步方式,通过js获取form中所有input、select等组件的值,将这些值组成Json格式,通过异步的方式与服务器端进行交互,
一般将表单数据传送给服务器端,服务器端处理数据并返回结果信息等

<form id="form"  method="post">
   <input type="text" name="name" id="name"/>
</form>
  var params = {"name", $("#name").val()}
 $.ajax({
      type: "POST",
      url: "/url.do",
      data: params,
      dataType : "json",
      success: function(respMsg){
      }
   });
              

页面无跳转

如果通过form表单提交请求服务端去下载文件,这时当前页面不会发生跳转,服务端返回void,通过response 去写文件数据,
页面会显示下载文件。

<form action="/url.do" method="post">
   <input type="text" name="name"/>
   <input type="submit" value="提交">
</form>

@RequestMapping(value = "/url")
    public void exportFile(HttpServletRequest req, HttpServletResponse response, String rptId)
            throws Exception {
        OutputStream out = null;
        try {
            String rptName = "file";
            String fileName = new String((rptName + excelAble.getFileSuffix()).getBytes("GBK"),
                    "8859_1");
            response.reset();
            response.setContentType("application/octec-stream");
            response.setHeader("Content-disposition", "attachment; filename=" + fileName);
            out = response.getOutputStream();
            excelAble.exportFile(out);
        } catch (Exception e) {
            logger.error(e);
        } finally {
            if (out != null) {
                out.close();
            }
        }
    }
              

form表单上传文件

使用form表单进行上传文件需要为form添加enctype="multipart/form-data" 属性,除此之外还需要将表单的提交方法改成post,
如下 method="post", input type的类型需要设置为file

 <form action="/url.do" enctype="multipart/form-data" method="post">
     <input type="file" name="name"/>
     <input type="submit" value="提交">
   </form>
              

相关文章:

  • 关于struts2中ActionContext的实现原理
  • Struts2 form表单的action和onsubmit事件说明
  • Struts2(二)---将页面表单中的数据提交给Action
  • UUID
  • BigInteger
  • 大数的阶乘位数
  • 9999阶乘位数
  • MyEclipse2017 下'Publishing to Tomcat 8.5。。。'has encountered a problem解决办法
  • Could not publish to the server tomcat version 8.5 requires java se7 or later......
  • mysql中find_in_set()函数的使用
  • myeclipse部署在tomcat下没有class文件
  • java +vtk.jar+dlls,环境部署配置遇到的问题
  • python安装numpy包教程等其他相关包
  • 解决pycharm无法调用pip安装的包
  • pycharm 2018 永久激活
  • 【译】JS基础算法脚本:字符串结尾
  • android高仿小视频、应用锁、3种存储库、QQ小红点动画、仿支付宝图表等源码...
  • Computed property XXX was assigned to but it has no setter
  • Elasticsearch 参考指南(升级前重新索引)
  • ES学习笔记(12)--Symbol
  • JavaScript 基础知识 - 入门篇(一)
  • JavaScript设计模式与开发实践系列之策略模式
  • LeetCode29.两数相除 JavaScript
  • mysql_config not found
  • open-falcon 开发笔记(一):从零开始搭建虚拟服务器和监测环境
  • quasar-framework cnodejs社区
  • Sass Day-01
  • Spring Cloud Alibaba迁移指南(一):一行代码从 Hystrix 迁移到 Sentinel
  • 简单基于spring的redis配置(单机和集群模式)
  • 如何抓住下一波零售风口?看RPA玩转零售自动化
  • 一起来学SpringBoot | 第三篇:SpringBoot日志配置
  • 云栖大讲堂Java基础入门(三)- 阿里巴巴Java开发手册介绍
  • C# - 为值类型重定义相等性
  • 阿里云服务器购买完整流程
  • 大数据全解:定义、价值及挑战
  • ​flutter 代码混淆
  • ​iOS实时查看App运行日志
  • #etcd#安装时出错
  • $.ajax()方法详解
  • (4)事件处理——(6)给.ready()回调函数传递一个参数(Passing an argument to the .ready() callback)...
  • (附源码)php投票系统 毕业设计 121500
  • (机器学习的矩阵)(向量、矩阵与多元线性回归)
  • (转)清华学霸演讲稿:永远不要说你已经尽力了
  • (轉)JSON.stringify 语法实例讲解
  • .NET 发展历程
  • .NET/C# 使窗口永不获得焦点
  • .NET/C# 中设置当发生某个特定异常时进入断点(不借助 Visual Studio 的纯代码实现)
  • .NET多线程执行函数
  • .net和php怎么连接,php和apache之间如何连接
  • .NET微信公众号开发-2.0创建自定义菜单
  • .net之微信企业号开发(一) 所使用的环境与工具以及准备工作
  • .NET中使用Redis (二)
  • [ C++ ] STL_stack(栈)queue(队列)使用及其重要接口模拟实现
  • [20170705]lsnrctl status LISTENER_SCAN1
  • [3D基础]理解计算机3D图形学中的坐标系变换