<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
!~!
</head>
<body>
<p>
你猜我多大年纪了?(1-100)
</p>
<form action="numberC.jsp" method="post" name=from>
<input name="text1" type="text" >
<input type="submit" name="start" value="Start">
</form>
<%
int number=(int)(Math.random());
%>
<p> 结果:</p>
</body>
</html>
——————————————————————————————————————
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
~!~
<body>
<%
String str=request.getParameter("text1");
int gN=Integer.parseInt(str);
Integer key=(Integer)session.getAttribute("nembur");
int newNum=key;
if(newNum==gN)
{
response.sendRedirect("correct.jsp");
}
else
{
if(newNum>gN)
{
response.sendRedirect("Max.jsp");
}
else
{
response.sendRedirect("Min.jsp");
}
}
%>
</body>
</html>
————————————————————————————
第一部分没问题,输入数值,点击Start后也能跳转,但在计算页面numberC部分 报500错误!错误内容如下
————————————————————————————
type Exception report
message An exception occurred processing JSP page /numberC.jsp at line 10
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /numberC.jsp at line 10
7: String str=request.getParameter("text1");
8: int gN=Integer.parseInt(str);
9: Integer key=(Integer)session.getAttribute("nembur");
10: int newNum=key;
11: if(newNum==gN)
12: {
13: response.sendRedirect("correct.jsp");
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
java.lang.NullPointerException
org.apache.jsp.numberC_jsp._jspService(numberC_jsp.java:73)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.30 logs.
请各位大神帮忙看下,我的问题出在哪?
------解决方案--------------------------------------------------------
nembur,是不是错了? number?
------解决方案--------------------------------------------------------
<%
int number=(int)(Math.random());
session.setAttribute("number",number);
%>