帮忙 jsp程序的一个问题。

来源:百度知道 编辑:UC知道 时间:2024/05/21 07:22:50
一个测试类
package example;
public class Sum {
public Sum() {
}
public int add(int x,int y)
{ return x+y;}
}
已正确部署,jsp代码如下;
<%@page language="java" contentType="text/html;charset=gb2312" import="example.Sum" %>
<html>
<head> <title>dddddd</title>
</head>
<body>
调用类的方法.返回值修改后的.
<%=Sum.add(10,6)%>
</body>
</html> 老是出错。如下方法有什么问题:
<%aa=new example.Sum()%>
<%=aa.add(10,6)%> 高手帮忙看看。还有别的方法。

调用类的方法.返回值修改后的.
<%=Sum.add(10,6)%>
这句调用,应该是调用类的静态方法吧
把他改成静态的
public staitc int add(int x,int y)
{ return x+y;}
}

package example;
public class Sum {
public Sum() {
}
public int add(int x,int y)
{ return x+y;}
}
已正确部署,jsp代码如下;
<%@page language="java" contentType="text/html;charset=gb2312" import="example.Sum" %>
<html>
<head> <title>dddddd</title>
</head>
<body>
调用类的方法.返回值修改后的.
<%=Sum.add(10,6)%>
</body>
</html> 老是出错。如下方法有什么问题:
<%aa=new example.Sum()%>
<%=aa.add(10,6)%> 高手帮忙看看。还有别的方法。
我觉得是没有弄清楚jaVA啊
上面说的可以解决问题