当前位置: 技术问答>java相关
初写JavaBean,遇到了障碍,大家帮忙给看看
来源: 互联网 发布时间:2015-04-24
本文导语: MyBean.java ---------------------------------------------------------------------- public class MyBean { private long id; private String sex; private String name; private int age; public void setId(long l) { id=l; } public...
MyBean.java
----------------------------------------------------------------------
public class MyBean
{
private long id;
private String sex;
private String name;
private int age;
public void setId(long l)
{
id=l;
}
public long getId()
{
return id;
}
public void setSex(String s)
{
if (s!="male"|s!="female")
{
System.out.println("Sex column is not formatted");
System.exit(0);
}
sex=s;
}
public String getSex()
{
return sex;
}
public void setName(String s)
{
name=s;
}
public String getName()
{
return name;
}
public void setAge(int i)
{
if (i>=23&&i
------------------------------------------------------------------------
浏览器启动BeanTest.jsp,出错,信息如下:
-----------------------------------------------------------------------
Compilation of 'C:BEAwlserver6.1configSUNapplicationsDefaultWebAppWEB-INF_tmp_war_DK_DK_DefaultWebAppjsp_servlet_beantest.java' failed:
--------------------------------------------------------------------------------
C:BEAwlserver6.1configSUNapplicationsDefaultWebAppWEB-INF_tmp_war_DK_DK_DefaultWebAppjsp_servlet_beantest.java:89: cannot resolve symbol
probably occurred due to an error in /BeanTest.jsp line 4:
C:BEAwlserver6.1configSUNapplicationsDefaultWebAppWEB-INF_tmp_war_DK_DK_DefaultWebAppjsp_servlet_beantest.java:90: cannot resolve symbol
probably occurred due to an error in /BeanTest.jsp line 4:
C:BEAwlserver6.1configSUNapplicationsDefaultWebAppWEB-INF_tmp_war_DK_DK_DefaultWebAppjsp_servlet_beantest.java:93: cannot resolve symbol
probably occurred due to an error in /BeanTest.jsp line 4:
C:BEAwlserver6.1configSUNapplicationsDefaultWebAppWEB-INF_tmp_war_DK_DK_DefaultWebAppjsp_servlet_beantest.java:95: cannot resolve symbol
probably occurred due to an error in /BeanTest.jsp line 4:
--------------------------------------------------------------------------------
Full compiler error(s):
C:BEAwlserver6.1configSUNapplicationsDefaultWebAppWEB-INF_tmp_war_DK_DK_DefaultWebAppjsp_servlet_beantest.java:89: cannot resolve symbol
symbol : class MyBean
location: class jsp_servlet._beantest
MyBean MyBean = null; //[ /BeanTest.jsp; Line: 4]
^
C:BEAwlserver6.1configSUNapplicationsDefaultWebAppWEB-INF_tmp_war_DK_DK_DefaultWebAppjsp_servlet_beantest.java:90: cannot resolve symbol
symbol : class MyBean
location: class jsp_servlet._beantest
MyBean = (MyBean)pageContext.getAttribute("MyBean"); //[ /BeanTest.jsp; Line: 4]
^
C:BEAwlserver6.1configSUNapplicationsDefaultWebAppWEB-INF_tmp_war_DK_DK_DefaultWebAppjsp_servlet_beantest.java:93: cannot resolve symbol
symbol : class MyBean
location: class jsp_servlet._beantest
MyBean = (MyBean)pageContext.getAttribute("MyBean"); //[ /BeanTest.jsp; Line: 4]
^
C:BEAwlserver6.1configSUNapplicationsDefaultWebAppWEB-INF_tmp_war_DK_DK_DefaultWebAppjsp_servlet_beantest.java:95: cannot resolve symbol
symbol : class MyBean
location: class jsp_servlet._beantest
MyBean = new MyBean(); //[ /BeanTest.jsp; Line: 4]
^
4 errors
-------------------------------------------------------------------------
请解释一下出错原因,并修正,谢谢大家
----------------------------------------------------------------------
public class MyBean
{
private long id;
private String sex;
private String name;
private int age;
public void setId(long l)
{
id=l;
}
public long getId()
{
return id;
}
public void setSex(String s)
{
if (s!="male"|s!="female")
{
System.out.println("Sex column is not formatted");
System.exit(0);
}
sex=s;
}
public String getSex()
{
return sex;
}
public void setName(String s)
{
name=s;
}
public String getName()
{
return name;
}
public void setAge(int i)
{
if (i>=23&&i
------------------------------------------------------------------------
浏览器启动BeanTest.jsp,出错,信息如下:
-----------------------------------------------------------------------
Compilation of 'C:BEAwlserver6.1configSUNapplicationsDefaultWebAppWEB-INF_tmp_war_DK_DK_DefaultWebAppjsp_servlet_beantest.java' failed:
--------------------------------------------------------------------------------
C:BEAwlserver6.1configSUNapplicationsDefaultWebAppWEB-INF_tmp_war_DK_DK_DefaultWebAppjsp_servlet_beantest.java:89: cannot resolve symbol
probably occurred due to an error in /BeanTest.jsp line 4:
C:BEAwlserver6.1configSUNapplicationsDefaultWebAppWEB-INF_tmp_war_DK_DK_DefaultWebAppjsp_servlet_beantest.java:90: cannot resolve symbol
probably occurred due to an error in /BeanTest.jsp line 4:
C:BEAwlserver6.1configSUNapplicationsDefaultWebAppWEB-INF_tmp_war_DK_DK_DefaultWebAppjsp_servlet_beantest.java:93: cannot resolve symbol
probably occurred due to an error in /BeanTest.jsp line 4:
C:BEAwlserver6.1configSUNapplicationsDefaultWebAppWEB-INF_tmp_war_DK_DK_DefaultWebAppjsp_servlet_beantest.java:95: cannot resolve symbol
probably occurred due to an error in /BeanTest.jsp line 4:
--------------------------------------------------------------------------------
Full compiler error(s):
C:BEAwlserver6.1configSUNapplicationsDefaultWebAppWEB-INF_tmp_war_DK_DK_DefaultWebAppjsp_servlet_beantest.java:89: cannot resolve symbol
symbol : class MyBean
location: class jsp_servlet._beantest
MyBean MyBean = null; //[ /BeanTest.jsp; Line: 4]
^
C:BEAwlserver6.1configSUNapplicationsDefaultWebAppWEB-INF_tmp_war_DK_DK_DefaultWebAppjsp_servlet_beantest.java:90: cannot resolve symbol
symbol : class MyBean
location: class jsp_servlet._beantest
MyBean = (MyBean)pageContext.getAttribute("MyBean"); //[ /BeanTest.jsp; Line: 4]
^
C:BEAwlserver6.1configSUNapplicationsDefaultWebAppWEB-INF_tmp_war_DK_DK_DefaultWebAppjsp_servlet_beantest.java:93: cannot resolve symbol
symbol : class MyBean
location: class jsp_servlet._beantest
MyBean = (MyBean)pageContext.getAttribute("MyBean"); //[ /BeanTest.jsp; Line: 4]
^
C:BEAwlserver6.1configSUNapplicationsDefaultWebAppWEB-INF_tmp_war_DK_DK_DefaultWebAppjsp_servlet_beantest.java:95: cannot resolve symbol
symbol : class MyBean
location: class jsp_servlet._beantest
MyBean = new MyBean(); //[ /BeanTest.jsp; Line: 4]
^
4 errors
-------------------------------------------------------------------------
请解释一下出错原因,并修正,谢谢大家
|
还有,你的实例名称和类名一样,是不是这个问题?改一下看看
|
1 是否编译
2 看看路径对不对
2 看看路径对不对
|
好像是id="MyBean"的问题,另外你还可以在Bean里写个main方法测试一下先