• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Error on basic jsp...

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Carmen Brianick
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Carmen,

You are right about the second question too.

Thanks
Chandu
 
Carmen Brianick
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your confirmation of my answers Chandu.

Regards,
Carmen
 
So you made a portal in time and started grabbing people. This tiny ad thinks that's rude:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic