jQuery in Action, 2nd edition*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes java bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "java bean " Watch "java bean " New topic
Author

java bean

mayank jamindar
Ranch Hand

Joined: Aug 01, 2005
Posts: 38
Hi,
Plz help me answer the following query:
Consider the code for a java bean
(public class TicketBean
{
int price;
String name;
// assume usual getters and setters.
}

):
Also consider the following code for ticketview.jsp:

<html>
<head></head>
<body>
<jsp:useBean id="ticket" class="TicketBean"/>
<jsp:setProperty name="ticket" property="*"/>
Name : <%=ticket.getName()%>
Price : <%=ticket.getPrice()%>
</body>
<html>
Which of the following lines will be in the output of the jsp page, if it is accessed through URL:
http://servername/ticketview.jsp?name=AAA


Do you think Since Price is not set It will give Error? If now what will happen when value is accessed.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

No error. I'd expect it to print null to the screen.

Why don't you try it out? It would be good practice.


A good workman is known by his tools.
mayank jamindar
Ranch Hand

Joined: Aug 01, 2005
Posts: 38
Any More Suggestions.....
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

(never mind)
[ January 26, 2006: Message edited by: Marc Peabody ]
Patrick Williams
Ranch Hand

Joined: Apr 03, 2005
Posts: 213
I haven't tried this, but wouldn't it print:

Name: AAA
Price: 0

???

I would assume that int would initialize to 0 because price is a class level member. Has anyone tried it?


Patrick<br /> <br />SCJP/SCWCD/SCBCD/SCDJWS/SCEA<br /> <br />Currently working on:<br />SCJP 6
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Ah, yes. Patrick is correct. I did not see that price was an int - that's usually not the type you would use in the real world for price.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java bean