aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Error on basic jsp... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Error on basic jsp..." Watch "Error on basic jsp..." New topic
Author

Error on basic jsp...

Carmen Brianick
Ranch Hand

Joined: Feb 23, 2006
Posts: 67
Hi, I'm getting a "cannot resolve symbol getEmpID()" error when I click submit on my html page. I have listed my short html page, jsp, and bean code below. Thanks so much for your great help! -Carmen
***html code***
<html><body><form action="TestBean.jsp">
name: <input type="text" name="name">
ID#: <input type="text" name="empID">
<input type="submit">
</form></body></html>

***jsp***
<html><body><jsp:useBean id="person" type="foo.Person" class="foo.Employee">
<jsp:setProperty name="person" property="*"/>
</jsp:useBean>
User's name is <%=person.getName()%><br>
ID is <%=person.getEmpID()%>
</body><html>

*** Person bean ***
package foo;
public abstract class Person{
private String name;
public void setName(String name){this.name = name;}
public String getName(){return name;}
}

*** Employee bean ***
package foo;
public class Employee extends Person{
private int empID;
public void setEmpID(int empID){this.empID=empID;}
public int getEmpID(){return empID;}
}
Carmen Brianick
Ranch Hand

Joined: Feb 23, 2006
Posts: 67
Hi, how come if I use '<jsp:getProperty name="person" property="empID"/>' it would work? Why won't <%=person.getEmpID()%> work?

Thanks so much,
Carmen
Chandra Sagi
Ranch Hand

Joined: May 05, 2005
Posts: 162
Your reference type is Person which doesn't know about empID. empID is defined in your Employee class. Change your type to foo.Employee and it should work

Thanks
Chandu
Carmen Brianick
Ranch Hand

Joined: Feb 23, 2006
Posts: 67
Hi Chandra, thanks for your answer! I still have 2 questions I hope you can help on:

1. Why does this work, even though type is still 'foo.Person'? :
<jsp:useBean id="person" type="foo.Person" class="foo.Employee">
<jsp:setProperty name="person" property="*"/></jsp:useBean>
empID is: <jsp:getProperty name="person" property="empID"/>

2. In Person p = new Employee();// p is a Person and does not have any features or know about Employee, am I right?

Thanks so much,
Carmen
srini E
Greenhorn

Joined: Feb 18, 2006
Posts: 10
I'd really like to know the explanation for that....

Reason: HFJS Page 414, last but one bullet reads as
-- if you specify a "type" attribute in the <jsp:useBean>, you can set properties in <jsp:setProperty> ONLY on properties of the "type", but NOT on properties that exist only in the actual "class" type (In other words, polymorphism and normal java type rules apply).

Going by above i'm wordering how is that your get value is giving empId.??

will appreciate your response..


learn-->practice-->Improvise-->repeat<br /> <br />Thanks,<br />Srini
Carmen Brianick
Ranch Hand

Joined: Feb 23, 2006
Posts: 67
Hi srinivas, I believe I may have answered my own question #1 b/c for:
<jsp:getProperty name="person" property="empID"/>

the generated servlet code is:

out.write(org.apache.jasper.runtime.JspRuntimeLibrary.toString((((foo.Employee)_jspx_page_context.findAttribute("person")).getEmpID())));

So I see (foo.Employee) here doing some casting on the object, so maybe this is it.

This is as far as I know, maybe someone else can comment more?

Anyway, srinivas, I hope this helps, btw, do you have any comment about my question #2?

Thanks,
Carmen
Chandra Sagi
Ranch Hand

Joined: May 05, 2005
Posts: 162
Hi Carmen,

You are right about the second question too.

Thanks
Chandu
Carmen Brianick
Ranch Hand

Joined: Feb 23, 2006
Posts: 67
Thank you for your confirmation of my answers Chandu.

Regards,
Carmen
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error on basic jsp...
 
Similar Threads
Concrete class problem in EL
Scriptless JSPs
jsp:setProperty
jsp:useBean doubt
Need help with a small java tutorial.