在同一页面中JSP获取JS取到的值

<%@ 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>
 

 

如果取不到值有可能是<form action="main/test.jsp" method="post" id="myForm">出错,有可能是提交页面的路径不正确,我就是因为这个原因  搞了很久,压根就没有冲路径上面去想          以后测试的时候,一定看浏览器的路径......

你可能感兴趣的:(jsp)