This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes mock question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "mock question" Watch "mock question" New topic
Author

mock question

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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>
James Kwan
Ranch Hand

Joined: Dec 06, 2001
Posts: 51
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
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

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.


Groovy
Ray Smilgius
Ranch Hand

Joined: Jan 29, 2001
Posts: 120
Dont forget to terminate the end of the jsp:setproperty
<jsp:setProperty name="test" property="*"/>
peace


SCJO, SCJD, SCWCD, I-Net+, A+, Network+, MCSD, MCDBA, MCP, MCT
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
no answer???
alex lamb
Greenhorn

Joined: May 31, 2002
Posts: 6
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: mock question
 
Similar Threads
jsp:useBean Example
question about jsp:useBean from mock test by anand chawala
a question need help
Mock Exam Question
one question about JavaBean