//TestBean.java
package test; 
public class TestBean{ 
private String name = null; 
public TestBean(String strName_p){ 
this.name=strName_p; 

public TestBean(){ 

public void setName(String strName_p){ 
this.name=strName_p; 

public String getName(){ 
return this.name; 

public int getRs(int a,int b)
{
 return a+b; 
}

-------------------------------------------------
///TestBean.jsp
<%@ page import="test.TestBean" %> 
<html>
<body>
<center> 
<% 
TestBean testBean=new TestBean("This is a test java bean."); 
%> 
Java bean name is: <%=testBean.getName()%> 
The Res is: <%=testBean.getRS(23,25)%> 
</center>
</body>
</html> 
------------------------------------------
报错如下:
An error occurred at line: 7 in the jsp file: /TestBean.jsp
The method getRS(int, int) is undefined for the type TestBean

解决方案 »

  1.   

    getRS你的函数名错误,大小写,->getRs
      

  2.   

    1楼朋友说的是一个情况
    但我没看到你的Bean类中有
    private String rs;
    定义的相应的属性啊!
    你仔细检查一下
      

  3.   

    错误信息翻译中文为:发生错误行:7 JSP的文件: / TestBean.jsp 该方法getRS (整数,整数)是未定义类型TestBean”
    你倒数第四行的方法中getRS(23,25)的S应该是小写。如果还运行不出来,加入
    <jsp:useBean id=“自定义名” scope=“session” class=”包名.bean类名”/>到jsp页面头中
    用<% 自定义名.setName("This is a test java bean.")%>来传递值。