JSP出现空指针异常 10
Jisuanqi2.jsp<%@pagecontentType="text/html;charset=gb2312"%><%@pageimport="first.comp...
Jisuanqi2.jsp
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="first.computer.Jisuanqi" %>
<html>
<head>
<style type="text/css">
<!--
.STYLE1 {font-family: "宋体"}
-->
</style>
</head>
<BODY bgcolor=cyan><Font size=3>
<form name="info" method="post" action="">
<label>
<input type="text" name="nub1" >
</label>
<label>
<select name="operator">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
</label>
<label>
<input type="text" name="nub2" >
</label>
<label>
<input type="submit" name="Submit" value="提交">
</label>
</form>
<p>
<jsp:useBean id="j" class="first.computer.Jisuanqi" scope="page"/>
<jsp:setProperty name="j" property="*"/>
第一个数是<span class="STYLE1">:</span>
<jsp:getProperty name="j" property="nub1"/>
</p>
<p>第二个数是<span class="STYLE1">:</span>
<jsp:getProperty name="j" property="nub2"/>
</p>
<p>结果是<span class="STYLE1">:</span>
<jsp:getProperty name="j" property="nub1"/>
<%=j.getOperator() %>
<jsp:getProperty name="j" property="nub2"/>
=
<jsp:getProperty name="j" property="result"/>
</p>
</body>
</html>
Jisuanqi2.java
package first.computer;
public class Jisuanqi
{
double nub1,nub2;
double result=0;
String operator;
public Jisuanqi()
{
nub1=0;
nub2=0;
result=0;
}
public double getNub1()
{
return nub1;
}
public void setNub1(double newnub1)
{
nub1=newnub1;
}
public double getNub2()
{
return nub2;
}
public void setNub2(double newnub2)
{
nub2=newnub2;
}
public String getOperator()
{
return operator;
}
public void setOperator(String newOperator)
{
operator=newOperator;
}
public double getResult()
{
if (operator.equals("+"))
{
result=nub1+nub2;
//return result;
}
if (operator.equals("-"))
{
result=nub1-nub2;
// return result;
}
if (operator.equals("*"))
{
result=nub1*nub2;
//return result;
}
if (operator.equals("/"))
{
result=nub1/nub2;
//return result;
}
return result;
}
}
Jisuanqi2.java文件编译后生成class文件 ,启动服务器运行后出现空指针异常,反复调试,还是不行,不知道怎么回事,望高手指点
这是使用javabean编译的一个简易计算器 展开
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="first.computer.Jisuanqi" %>
<html>
<head>
<style type="text/css">
<!--
.STYLE1 {font-family: "宋体"}
-->
</style>
</head>
<BODY bgcolor=cyan><Font size=3>
<form name="info" method="post" action="">
<label>
<input type="text" name="nub1" >
</label>
<label>
<select name="operator">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
</label>
<label>
<input type="text" name="nub2" >
</label>
<label>
<input type="submit" name="Submit" value="提交">
</label>
</form>
<p>
<jsp:useBean id="j" class="first.computer.Jisuanqi" scope="page"/>
<jsp:setProperty name="j" property="*"/>
第一个数是<span class="STYLE1">:</span>
<jsp:getProperty name="j" property="nub1"/>
</p>
<p>第二个数是<span class="STYLE1">:</span>
<jsp:getProperty name="j" property="nub2"/>
</p>
<p>结果是<span class="STYLE1">:</span>
<jsp:getProperty name="j" property="nub1"/>
<%=j.getOperator() %>
<jsp:getProperty name="j" property="nub2"/>
=
<jsp:getProperty name="j" property="result"/>
</p>
</body>
</html>
Jisuanqi2.java
package first.computer;
public class Jisuanqi
{
double nub1,nub2;
double result=0;
String operator;
public Jisuanqi()
{
nub1=0;
nub2=0;
result=0;
}
public double getNub1()
{
return nub1;
}
public void setNub1(double newnub1)
{
nub1=newnub1;
}
public double getNub2()
{
return nub2;
}
public void setNub2(double newnub2)
{
nub2=newnub2;
}
public String getOperator()
{
return operator;
}
public void setOperator(String newOperator)
{
operator=newOperator;
}
public double getResult()
{
if (operator.equals("+"))
{
result=nub1+nub2;
//return result;
}
if (operator.equals("-"))
{
result=nub1-nub2;
// return result;
}
if (operator.equals("*"))
{
result=nub1*nub2;
//return result;
}
if (operator.equals("/"))
{
result=nub1/nub2;
//return result;
}
return result;
}
}
Jisuanqi2.java文件编译后生成class文件 ,启动服务器运行后出现空指针异常,反复调试,还是不行,不知道怎么回事,望高手指点
这是使用javabean编译的一个简易计算器 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询