Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL question

 
H Singh
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jamed
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
H Singh
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic