wood burning stoves*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes EL usage 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 "EL usage" Watch "EL usage" New topic
Author

EL usage

trivikram Kumar
Ranch Hand

Joined: Feb 21, 2005
Posts: 172
Hi pals,
I tried a lot to get the request attributes using EL.
I got it using scripting.
Its the same as example on page 366 in HF.
When i used EL it gives an error saying :
"Unable to find a value for "Dog" in object of class "com.example.person" using operator ".""
I am breaking my head since yesterday morning..but could not get it right.
If anyone knows how to solve this,please help me out as I am stuck here and am not able to proceed further.

Thanks in advance,
Javainn


Javainn<br /> <br />SCJP,SCWCD,SCBCD,<br />ICED (IBM-287,IBM-484,IBM-486)
IBM certified in DB2 V 8.1 Family Fundamentals (IBM 700)
Ganeshji Marwaha
Greenhorn

Joined: Sep 16, 2004
Posts: 27
You might try posting some code, so that we can try and figure out if there is any issue.


-- Ganeshji Marwaha<br />SCJP<br />SCWCD<br />SCBCD<br />MCP, MCP+SB, MCSD
trivikram Kumar
Ranch Hand

Joined: Feb 21, 2005
Posts: 172
Hi Ganesh,

here is my complete code.
Please try to figure out where the problem lies.
I am getting it worked with ${person.name} but not with ${person.dog.name}
If there is any doubt regarding my presentation..please ask me.

Thanks in advance,
javainn

first file:

form1.html(I am calling this from IE)

<html>
<body>
<form method="post"action="Test.do">
<h1>Testing usage of Scriptless JSP's</h1>
<input type="submit"value="submit">
</form>
</body>
</html>

2nd file-Test.java(Control goes to this servlet next)

package com.example;
import com.example.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class Test extends HttpServlet
{
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException,
IOException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
com.example.person p=new com.example.person();
p.setName("JIMMY");
com.example.Dog dog=new com.example.Dog();
dog.setName("Tommy");
p.setDog(dog);
request.setAttribute("person",p);
RequestDispatcher view=request.getRequestDispatcher("final.jsp");
view.forward(request,response);
}
}

3rd file ( Dog.java)
package com.example;
public class Dog{
static String name;
public static String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
}

last file(final.jsp)
<html>
<body>
<h1>The Name Is:</h1>
${person.dog.name}
</body>
</html>

her eits giving the error.

The directory com is under web-apps,app-name,classes.

web.xml for your ref is :

<web-app xml="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>testname</servlet-name>
<servlet-class>com.example.Test</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>testname</servlet-name>
<url-pattern>/Test.do</url-pattern>
</servlet-mapping>
</web-app>

[ April 01, 2005: Message edited by: S javainn ]
[ April 02, 2005: Message edited by: S javainn ]
Jose Esteban
Ranch Hand

Joined: Nov 28, 2004
Posts: 102
The person class is missing in your post.
Bassam Zahid
Ranch Hand

Joined: Mar 09, 2005
Posts: 61
Please note that "Dog" object is not placed in your "Person" bean. What you are doing is just setting it as an attribute. Try accessing the "Dog" object through scriptlets. Also declare the "Dog" object in the person class as an instance member then you could use the above posted EL code.

Thanks.


BS<br />SCJP 1.4 88%<br />SCWCD 1.4 86%
trivikram Kumar
Ranch Hand

Joined: Feb 21, 2005
Posts: 172
Sorry....pals..this is my persons class
Hi Bassam,
I declared that i forgot to post the person class.
Can you please check it now and let me know where the problem is...
here is my persons class

package com.example;

public class person{
private String name;
public static Dog dog=null;

public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
public static Dog getDog(){
return dog;
}
public void setDog(Dog dog){

this.dog=dog;
}
}
[ April 01, 2005: Message edited by: S javainn ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: EL usage
 
Similar Threads
What needs to be done to display EL expression
Url problem
Jstl and EL
problems with EL in jsp and java bean
How to run simple JSTL page?