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 Standard actions - doubt in HFS - page 414 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 "Standard actions - doubt in HFS - page 414" Watch "Standard actions - doubt in HFS - page 414" New topic
Author

Standard actions - doubt in HFS - page 414

Ritu varada
Ranch Hand

Joined: Sep 08, 2004
Posts: 117
In HFS book for standard actions, it says

--If you specify a "type" attribute in <jsp:useBean>, you can set properties in <jsp:setProperty> ONLY on the properties of the type, but NOT ON properties that exist only in the actual "class" type. So, for the below example, I should be able to set name property but not the empID becuase that is the property of the actual class...Could somebody clarify this for sure ? (I took this example from another post because this was exactly what I needed..Thanks Nithya..)

Abstract class - Person

package myclasses;

public abstract class Person{
private String name ;

public Person(){
System.out.println("Person Constructor");
}

public void setName(String name){
this.name= name ;
}

public String getName(){
return name;
}
}


Concrete subclass - Employee

package myclasses;

public class Employee extends Person{
private int empId;

public Employee(){
System.out.println("Employee Constructor");
}

public void setEmpId(int empId){
this.empId = empId;
}

public int getEmpId(){
return empId;
}
}


Servlet - EmployeeServlet

package myclasses;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class EmployeeServlet extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException{
Employee e =new Employee();
req.setAttribute("employee", e);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/EmployeeJsp.jsp");
rd.forward(req,res);
}
}



The JSP thats called EmployeeJsp
<html>
<body>
Testing the forwarded page
<jsp:useBean id="employee" type="myclasses.Person" scope="request"/>
<jsp:setProperty name="employee" property="name" value="Nithya"/>
<jsp:setProperty name="employee" property="empId" value="1"/>
The name is ${employee.name}
The empId is ${employee.empId}
</body>
</html>

My web.xml has:
<servlet>
<servlet-name>MyEmployee</servlet-name>
<servlet-class>myclasses.EmployeeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyEmployee</servlet-name>
<url-pattern>/MyServlet.do</url-pattern>
</servlet-mapping>

This does print the name and empID.


SCJP,SCWCD(1.4)
Ritu varada
Ranch Hand

Joined: Sep 08, 2004
Posts: 117
Kathy has already explained this in an earlier post.

http://www.coderanch.com/t/168204/java-Web-Component-SCWCD/certification/jsp-useBean-setProperty-HFS-query
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Standard actions - doubt in HFS - page 414