js打开新窗口并且POST传入参数
2017-04-22 14:33
309 查看
首先新建一个index.jsp,在里面添加一个form表单,和一个button。在form中设置method为POST,并且设置好action为需要跳转的jsp页面,target参数设为_blank,表示新打开一个窗口。然后为button添加响应事件,调用form的submit方法。index.jsp代码如下:
在要跳转的jsp页面中,添加两个type="hidden"的input用来接收传过来的参数,并且用js读取那两个input的值,然后在lable中显示出来,newPage.jsp代码如下:
点击按钮后:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> <script type="text/javascript"> function newPage(){ //var name=document.getElementById("name"); //var pwd=document.getElementById("pwd"); var newPage=document.getElementById("newPageForm"); newPage.submit(); //提交实现跳转 } </script> </head> <body> <form id="newPageForm" action="newPage.jsp" target="_blank" method="POST"> <label for="name">用户:</label> <input type="text" id="name" name="name"/> <br> <label for="pwd">密码:</label> <input type="text" id="pwd" name="password"/> </form> <button onClick="newPage()">打开新页面</button> </body> </html>
在要跳转的jsp页面中,添加两个type="hidden"的input用来接收传过来的参数,并且用js读取那两个input的值,然后在lable中显示出来,newPage.jsp代码如下:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.io.*,java.util.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <script type="text/javascript"> function setLabel(){ var theLabel=document.getElementById("content"); var name=document.getElementById("name").value; var pwd=document.getElementById("pwd").value; var content="我是"+name+"密码为"+pwd; theLabel.innerHTML=content; } </script> </head> <body onload="setLabel()"> <label id="content"></label> <input type="hidden" id="name" value="<%=request.getParameter("name")%>" /> <input type="hidden" id="pwd" value="<%=request.getParameter("password")%>"/> </body> </html>效果截图如下:
点击按钮后:
相关文章推荐
- JS: 打开新窗口时(open window),使用传递post参数
- js使用post 方式打开新窗口,隐藏Url参数
- 前端js再新窗口打开页面,以post传递参数方式
- js window.open打开新窗口 参数
- 在js 中window.open()打开新页面,post方式传递参数到新页面上
- js window.open打开新窗口 参数
- [js] post 方式打开新窗口
- js 用window.open打开新窗口,父窗口怎么向子窗口传值,子窗口怎么接收父窗口传来的参数
- js 用window.open(参数) 打开新窗口,在新窗口怎么获取传过来的参数
- 这篇文章主要介绍了js使用post 方式打开新窗口的相关资料,需要的朋友可以参考下
- CefSharp禁止弹出新窗体,在同一窗口打开链接,并且支持带type="POST" target="_blank"的链接
- js使用post 方式打开新窗口
- js打开新窗口并且居中显示
- POST形式 soapUI调用WebService的restful接口,传入json参数,并且返回json
- JS 打开一个模式窗口,使用Cookie传递一个参数
- js使用post 方式打开新窗口
- js使用post 方式打开新窗口
- 使用window.open打开新窗口,以post方式传参数
- EAS8.0,EAS8.2,WAF2,JS,打开新页面,打开新窗口,传递参数
- ASP.NET 后台打开新窗口 并控制窗口参数