• 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
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

mock question

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The contents of beans class are as follows:-
package projsp;
public class trying
{
private String name;
private int age;
public void setName(String n)
{
name=n;
}
public void setAge(int a)
{
age=a;
}

public int getAge()
{
return age;
}
public String getName()
{
return name;
}
}
The contents of test.jsp file are as follows:
<%@ page language="java" import="projsp.*" %>
<jsp:useBean id="test" class="projsp.trying" />
<html>
The Name is <getProperty name="test" property="name" />
The Age is < jsp:getProperty name="test" property="age" />
</html>
If a user types in http://servername:8080/test.jsp?name=Anand&age=22 the out put is

The correct answer is The Name is null and The Age is null as the properties are not
set prior to accessing them,adding <jsp:setProperty name="test" property="*">
would give output as The Name is Anand and The Age is 22

<b>why does'nt it print nae is null and age =0??</b>
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I ran into this question with the mock exam too. I think it may be an error since the default for age should be 0 as it is declared as an int. Can anyone clearify this?
-James
SCJP,SCJD,SCWCD
 
Ranch Hand
Posts: 8946
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
using <jsp:setProperty name="test" property="*"> will map the request parameters to the bean fields in this case name and age .so u will get anand and 22.
 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dont forget to terminate the end of the jsp:setproperty
<jsp:setProperty name="test" property="*"/>
peace
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no answer???
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All,
I agree with James as well. I just ran the example on Tomcat 4.0 . Returns 0 as we all expected it to.
alex
 
A feeble attempt to tell you about our stuff that makes us money
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic