JSP 有关<jsp:include>里的<jsp:param> 传参数 不知道为什么出 空指针
<html><head><title>Compute</title><metahttp-equiv="Content-Type"content="text/html"ch...
<html>
<head>
<title>Compute</title>
<meta http-equiv="Content-Type" content="text/html" charset="gb2312">
</head>
<body>
<form method="post" action="Compute.jsp">
请选择要做的运算
<p>
除法<input type="radio" name="compute" value="1">
<p>
乘法<input type="radio" name="compute" value="2">
<p>
被除数或被乘数
<input type="text" name="v1">
<p>
除数或乘数
<input type="text" name="v1">
<input type="submit" name="submit" value="计算结果">
</body>
</html>
以上是网页
下面是Compute.jsp
<%@page language="java"%>
<html>
<head>
<title>xixi</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<h1>
<%
String value1 = request.getParameter("value1");
String value2 = request.getParameter("value2");
%>
<% if(request.getParameter("compute").equals("1")){ %>
<jsp:include page="division.jsp" flush="true">
<jsp:param name="v1" value="<%=value1%>"/>
<jsp:param name="v2" value="<%=value2%>"/>
</jsp:include>
<% } else{ out.print("haha");
out.print(request.getParameter("compute"));
} %>
</h1>
</body>
再转到这里
<html>
<head>
<title>Divide</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<h1>
<%
String s = request.getParameter("v1");
out.println(s);
%>
</h1>
</body>
</html>
s 值就是null,为什么 request.getParameter("v1"); 取不到<jsp:param name="v1" value="<%=value1%>"/> 传过来的值啊,就是页面上输入的 展开
<head>
<title>Compute</title>
<meta http-equiv="Content-Type" content="text/html" charset="gb2312">
</head>
<body>
<form method="post" action="Compute.jsp">
请选择要做的运算
<p>
除法<input type="radio" name="compute" value="1">
<p>
乘法<input type="radio" name="compute" value="2">
<p>
被除数或被乘数
<input type="text" name="v1">
<p>
除数或乘数
<input type="text" name="v1">
<input type="submit" name="submit" value="计算结果">
</body>
</html>
以上是网页
下面是Compute.jsp
<%@page language="java"%>
<html>
<head>
<title>xixi</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<h1>
<%
String value1 = request.getParameter("value1");
String value2 = request.getParameter("value2");
%>
<% if(request.getParameter("compute").equals("1")){ %>
<jsp:include page="division.jsp" flush="true">
<jsp:param name="v1" value="<%=value1%>"/>
<jsp:param name="v2" value="<%=value2%>"/>
</jsp:include>
<% } else{ out.print("haha");
out.print(request.getParameter("compute"));
} %>
</h1>
</body>
再转到这里
<html>
<head>
<title>Divide</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<h1>
<%
String s = request.getParameter("v1");
out.println(s);
%>
</h1>
</body>
</html>
s 值就是null,为什么 request.getParameter("v1"); 取不到<jsp:param name="v1" value="<%=value1%>"/> 传过来的值啊,就是页面上输入的 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询