<%@ 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" οnchange="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" οnchange="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>