一个很菜的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>
...全文
81 7 点赞 打赏 收藏 举报
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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
有这么输入的吗?
而且你的应用程序配置都错了
  • 打赏
  • 举报
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2006-03-21 01:23
社区公告
暂无公告