一个很菜的jsp问题

gift1985 2006-03-21 01:23:54
一个很菜的问题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>
...全文
124 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
gift1985 2006-03-22
  • 打赏
  • 举报
回复
我换了TOMCAT5.0了可还是不行新的错误产生了
xiangbo520 2006-03-21
  • 打赏
  • 举报
回复
大哥,还在用4.0版本啊,不知道你的教材是哪年出版的,现在TOMCAT都已经5.5了。运行速度快了好多。赶紧换JDK5.0 和TOMCAT 5.5吧
xiongbing528 2006-03-21
  • 打赏
  • 举报
回复
<%@page import="ch06.SimpleCalculator.*" %>,
gift1985 2006-03-21
  • 打赏
  • 举报
回复
我绝的是配置的问题那位高手给指点指点呀!
scottwhb 2006-03-21
  • 打赏
  • 举报
回复
加上这句<%@page import="ch06.SimpleCalculator" %>,看看
gift1985 2006-03-21
  • 打赏
  • 举报
回复
补充一下,在浏览器输入的地址是http://localhost:8080/test/calculate.jsp
我的bean放在了Tomcat 4.1\webapps\ROOT\test\WEB-INF\classes\ch06下jsp程序放到了Tomcat 4.1\webapps\ROOT\test\下
fangshao 2006-03-21
  • 打赏
  • 举报
回复
在浏览齐输入的地址是C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\test\WEB-INF\classes\ch06
有这么输入的吗?
而且你的应用程序配置都错了

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧