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 EL question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "EL question " Watch "EL question " New topic
Author

EL question

H Singh
Ranch Hand

Joined: Apr 03, 2005
Posts: 34
Hey guys:

I am trying HFSJ example- page 371

I get : Music is : ${musicList["0"]} in the result instead of : Zero 7

Code is below:

package com.example;

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.example.*;

public class MusicServlet extends HttpServlet{

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{

String[] favoriteMusic = {"Zero 7","Tahiti 80","BT"};
request.setAttribute("musicList",favoriteMusic);

RequestDispatcher view = request.getRequestDispatcher("result.jsp");
view.forward(request,response);
}
}

result.jsp :

<html><body>
Music is : ${musicList["0"]}
</body></html>

What did i miss?

Thanks
HS
Anand Wadhwani
Ranch Hand

Joined: Mar 21, 2005
Posts: 151
You might have specified <el-ignored>true</ el-ignored> under jsp-config tag in your DD(web.xml). Please check that.

What servlet runner are you using? What JSP Specification does it supports? EL has been introduced only in JSP 2.0


SCWCD 1.4<br />---------------------<br />Ability is what you're capable of. <br />Motivation determines what you do. <br />Attitude determines how well you do it.<br />---------------------
Jamed
Ranch Hand

Joined: Apr 17, 2005
Posts: 35
this is what i have for the same application and it runs perfectly


package com.example.web;

import com.example.web.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class Test extends HttpServlet{

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{

String[] favoriteMusic= {"Zero 7","tahiti 80","BT","Frou Frou" };
request.setAttribute("musicList",favoriteMusic);

RequestDispatcher view= request.getRequestDispatcher("result.jsp");

view.forward(request,response);

}
}

***********************************************
<html><body>


Music is : ${musicList[1]}

</body></html>
***********************************************
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.4">

<servlet>
<servlet-name>BeansTest</servlet-name>
<servlet-class>com.example.web.Test</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>BeansTest</servlet-name>
<url-pattern>/Tester.do</url-pattern>
</servlet-mapping>

</web-app>
*********************

Test it with this http://localhost:8080/Music/Tester.do

let me know if it works
H Singh
Ranch Hand

Joined: Apr 03, 2005
Posts: 34
Hello Anand and Jamed
..thanks for the prompt reply..

i specified
<%@ page isELIgnored ="false" %> in my result.jsp and it worked.

I have Tomcat 5 installed ( Tomcat version 5 implements the Servlet 2.4 and JavaServer Pages 2.0 specifications )

Also, i read :
The default mode for JSP pages delivered with a Servlet 2.4 descriptor is to evaluate EL expressions.

And i do not have <el-ignored> true </el-ignored>..in my web.xml
Anand Wadhwani
Ranch Hand

Joined: Mar 21, 2005
Posts: 151
That's pretty strange!

Could you do me this favor: Copy your JSP in a brand new application having bare minimum web.xml, and remove <%@ page isELIgnored ="false" %> from the JSP and try to see if JSP works as expected.

I am asking this because by default EL evaluation should be turned on without specifying anything anywhere. Second this, since you specied isELIgnored=false page attribute in your JSP and it started working so now I am highly doubting that you have el-ignored set to true in your web.xml and that setting is getting overridden in your JSP with <%@ page isELIgnored ="false" %>

Thanks! and wish you luck for cracking this!
AmitKumar Jain
Ranch Hand

Joined: Jun 13, 2005
Posts: 95
I tried Hardarshan's example and its working fine in first place.
i.e it gives output Zero 7.
I used tomcat 5.0.28.


SCJP 1.4 : 91%
SCWCD 1.4 : 95%
SCBCD 1.3 : 95%
SCJP 6 Upgrade : 95%
Next SCBCD 1.5
Man is not finished when he is defeated. He is finished when he quits.
H Singh
Ranch Hand

Joined: Apr 03, 2005
Posts: 34
I tried again but same results.

I have Tomcat 5.0.28 installed.

code:

package com.example;

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.example.*;

public class MusicServlet extends HttpServlet{

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{

String[] favoriteMusic = {"Zero 7","Tahiti 80","BT"};
request.setAttribute("musicList",favoriteMusic);

RequestDispatcher view = request.getRequestDispatcher("result.jsp");
view.forward(request,response);
}
}

web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<servlet>
<servlet-name>MusicServlet1</servlet-name>
<servlet-class>com.example.MusicServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>MusicServlet1</servlet-name>
<url-pattern>/MusicServlet</url-pattern>
</servlet-mapping>

</web-app>


result.jsp

<%@ page isELIgnored="false" %>
<html><body>
Music is : ${musicList["0"]}
</body></html>

With <%@ page isELIgnored="false" %> in result.jsp, i get correct results.

Without <%@ page isELIgnored="false" %> in result.jsp, i get
Music is : ${musicList["0"]}

I don't know if there is any other global setting, which is causing EL to get ignored.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EL question
 
Similar Threads
HFSJ EL e.g. page 371
Unable to understand the solution on EL
Unable to display the content in array(created in the servlet)using JSP!
Getting a value from a checkbox
Can we put EL in a for loop?