求助:重定向页面与传递数据,失败!
本人是刚刚学JAVA,今天碰到个难题!解决不了啊!
重定向页面与传递数据,失败!
Index.jsp
1,产生随机数
2,传递给redirect.jsp
===下面是代码===
<%@ page contentType= "text/hmtl;charset=gb2312 "%>
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 重定向页面并传递数据!! </title>
</head>
<body>
<%
double i=Math.random();
%>
<JSP:forward page= "redirect.jsp ">
<JSP:param name= "number " value= " <%=i%> " />
</JSP:forward>
</body>
</html>
==========================================================
redirect.jsp
1,获得number的值
2,输出number的值
===下面是代码===
<%@ page contentType= "text/html;charset=gb2312 "%>
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 重定向页面2 </title>
</head>
<body>
<%
String str=request.getParameter( "number ");
if(str==null)
{
str= "0 ";
}
double n=Double.parseDouble(str);
%>
你传过来的数值是: <%=n%>
</body>
</html>
===========
最后输出的结果是问是否下载保存该文件,晕~~
------解决方案-------------------- 这样试试
%@ page language= "java " import= "java.util.* " pageEncoding= "UTF-8 "%>
首页
<html>
<head>
</head>
<body>
<%
double i = Math.random();
%>
<jsp:forward page= "test.jsp ">
<jsp:param name= "i " value= " <%=i %> "/>
</jsp:forward>
</body>
</html>
接受页
<%@ page language= "java " import= "java.util.* " pageEncoding= "UTF-8 "%>
<html>
<head>
</head>
<body>
<%
double i;
String str = request.getParameter( "i ");
if(str == null)
{
i = 0;
}
i = Double.parseDouble(str);
%>
显示 <%=i%>
</body>
</html>
我想可能是字符集的问题
------解决方案--------------------LZ这样写试下
<JSP:forward page= "redirect.jsp ">
<JSP:params>
<JSP:param name= "number " value= " <%=i%> " />
</JSP:params>
</JSP:forward>
------解决方案--------------------我顶