Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:useBean

 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
refering to Head Frst JSP Servlets ,,page 416.




What happens when these parts of servlet code Exceute? (person is abstract and eMployee is concrete).

1
Person p = new Employee();
p.setName("evan");
request.setAttribute("person", p);

2
Employee p = new Employee();
p.setName("evan");
request.setAttribute("person", p);

Should the results of both not be the same?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64632
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can find the java servlet that the JSP engine creates on behalf of the JSP and see what happens. If you are using Tomcat, it places these in the folder hierarchy under $CATALINA_HOME/work.
 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the book specified that the second option wud work..
tested that .. it doesnt.

Bear, why do you want me to look at the servlet code? The query was for the useBean.. anything specific you wanted to point to
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by geetu lalchandani:
the book specified that the second option wud work..
tested that .. it doesnt.


Can you explain what you mean by "it doesn't"?
Was an exception thrown? If so, can you post the stack trace?
What behviour were you expecting?
What actually happened.

I don't see anyting wrong with either example.

Originally posted by geetu lalchandani:

Bear, why do you want me to look at the servlet code? The query was for the useBean.. anything specific you wanted to point to


I think Bear's statement was more general.
Anytime you want to find out how the JSP compiler is dealing with a particular piece of code, the first place you should look is in the generated servlet code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic