File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 8919

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mock question