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

EL usage

 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might try posting some code, so that we can try and figure out if there is any issue.
 
trivikram Kumar
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The person class is missing in your post.
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
trivikram Kumar
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic