一个很菜的jsp问题
一个很菜的问题JSP和JAVABEAN
小弟写了一个简易计算器用的是JSP+JAVABEAN可是我在tomcat下运行
在浏览齐输入的地址是C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\test\WEB-INF\classes\ch06
出现提示是
An error occurred at line: 1 in the jsp file: /test/calculate.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\_\test\calculate_jsp.java:42: package ch06 does not exist
ch06.SimpleCalculator calculator = null;
^
An error occurred at line: 1 in the jsp file: /test/calculate.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\_\test\calculate_jsp.java:44: package ch06 does not exist
calculator = (ch06.SimpleCalculator) pageContext.getAttribute("calculator", PageContext.REQUEST_SCOPE); ^
An error occurred at line: 1 in the jsp file: /test/calculate.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\_\test\calculate_jsp.java:47: package ch06 does not exist
calculator = (ch06.SimpleCalculator) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "ch06.SimpleCalculator");
程序原代码是:
package ch06;
public class SimpleCalculator {
private String first;
private String second;
private double result;
private String operator;
public void setfirst(String first) {
this.first= first;
}
public void setsecond(String second) {
this.second = second;
}
public void setOperator(String operator) {
this.operator = operator;
}
public String getfirst() {
return this.first;
}
public String getsecond() {
return this.second;
}
public String getOperator() {
return this.getOperator();
}
public void calculate() {
double one=Double.parseDouble(first);
double tow=Double.parseDouble(second);
if(operator.equals("+"))
result = one+tow;
else if(operator.equals("-"))
result = one-tow;
else if(operator.equals("*"))
result = one*tow;
else if(operator.equals("/"))
result = one/tow;
}
public double getresult() {
return this.result;
}
}
<%@page contentType="text/html; charset=GBK"%>
<jsp:useBean id="calculator" scope="request" class="ch06.SimpleCalculator">
<jsp:setProperty name="calculator" property="*"/>
</jsp:useBean>
<html>
<head>
<title>简单计算器</title>
<meta content="text/html" http-equiv="Content-Type"/>
</head>
<body bgcolor="#ffffff">
<p align="center">简单得计算器</p>
<hr>
计算结果:<%
try{
calculator.calculate();
out.println(calculator.getfirst()+calculator.getOperator()+calculator.getsecond()+"="+calculator.getresult());
}catch(Exception e){
e.printStackTrace();
}
%>
<hr>
<form action="calculate.jsp" method="get">
<table>
<tr>
<td align="right">第一个参数</td>
<td><input type="text">
</td>
</tr>
<tr align="center">
<td><select name="operator">
<option value="+">
+</option>
<option>-</option>
<option>*</option>
<option>/</option>
</select></td>
</tr>
<tr>
<td align="right">第二个参数</td>
<td><input type="text">
</td></tr>
</table>
</form>
</body>
</html>