在JSP页面获取js中的变量值
2015-12-29 13:58
826 查看
<%@ 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 'test.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 get(){
document.getElementById("sel").value=document.getElementById("pull_down").value;
document.getElementById("myForm").submit();
}
</script>
</head>
<body>
同一页面中JSP获取JS取到的值 <br>
下拉框:<br/>
<select id="pull_down" onchange="get()">
<option>请选择</option>
<option value="1">一</option>
<option value="2">二</option>
<option value="3">三</option>
</select>
<form action="main/test.jsp" method="post" id="myForm">
<input type="hidden" id="sel" name="sel"/>
</form>
<%
out.print("JSP获取下拉框的value值:"+request.getParameter("sel"));
%>
</body>
</html>
<%
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 'test.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 get(){
document.getElementById("sel").value=document.getElementById("pull_down").value;
document.getElementById("myForm").submit();
}
</script>
</head>
<body>
同一页面中JSP获取JS取到的值 <br>
下拉框:<br/>
<select id="pull_down" onchange="get()">
<option>请选择</option>
<option value="1">一</option>
<option value="2">二</option>
<option value="3">三</option>
</select>
<form action="main/test.jsp" method="post" id="myForm">
<input type="hidden" id="sel" name="sel"/>
</form>
<%
out.print("JSP获取下拉框的value值:"+request.getParameter("sel"));
%>
</body>
</html>
相关文章推荐
- js数组操作大全
- 100多个基础常用JS函数和语法集合大全
- Day-8 中午。
- JSP页面显示含有中文名称(中文路径)出错?
- ObjC 利用反射和KVC实现嵌套对象序列化成JSON数据
- 轻松学习JavaScript二十八:DOM编程学习之事件处理函数
- 利用vnet在wifi局域网中模拟一个能返回json的服务器
- JS跨域调用之JSONP--动态Script标签方式实现跨域
- JS 正则表达式应用
- JavaScript学习 二、基础
- javascript跨域获取json数据
- js解决中文乱码
- js类、原型——学习笔记
- jsp中div遍历list集合
- JS实例操作QQ空间自动点赞方法
- JS判断当前使用的是哪个浏览器及其版本
- Drupal 引入JS文件的几种方式
- highcharts 绘制图标的JAVASCRIPT 类库 收藏
- Js 模拟鼠标点击事件
- JS获取浏览器信息