aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes How to enable EL in a jsp page? 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 "How to enable EL in a jsp page?" Watch "How to enable EL in a jsp page?" New topic
Author

How to enable EL in a jsp page?

Kathiresan Chinnasamy
Ranch Hand

Joined: Jan 01, 2008
Posts: 65
Hi Friends,

I am preparing for SCWCD, I have doubts in Expression Language(EL).
I am tried to execute the Simple Example of EL but the syntax prints in the page instead of the attribute value..

Here Example:

1. SimpleServelt.java

public void doGet(HttpservletRequest request, HttpServeltResponse response) throws ServletException, IOException {

Employee emp = new Emlpoyee(); //assume it is bean class ..
emp.setEmpId("100");
emp.setEmpName("Sample");

request.setAttribute("emp",emp);

RequestDispatcher dispatcher = request.getRequestDispatcher("/sample.jsp");
request.forword(request, response);
}
}

2. sample.jsp
<html>
<body>
The EmpId is : ${emp.empId};
The EmpName is : ${emp.empName};
</body>
</html>

3.output
The EmpId is : ${emp.empId};
The EmpName is : ${emp.empName};

Note:
I am using apache tomcat5.5 server
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Make sure that you have written your web.xml correctly. Check this FAQ.


[My Blog]
All roads lead to JavaRanch
Kathiresan Chinnasamy
Ranch Hand

Joined: Jan 01, 2008
Posts: 65
Hi Friends,

Still i am not getting the solution..
Is any jar file is needed for EL or Mapping to any TLD file?


please help me..

Thanks in Advance
Amol Fuke
Ranch Hand

Joined: Apr 08, 2005
Posts: 129
Hi ,

Can you use this
<c ut value="${emp.empId}" />
and add this taglib in your jsp :

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

Thanks,
Amol


"There are no mistakes, only lessons"
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Is any jar file is needed for EL or Mapping to any TLD file?

No. Please post your web.xml here.
[ June 25, 2008: Message edited by: Christophe Verre ]
Kathiresan Chinnasamy
Ranch Hand

Joined: Jan 01, 2008
Posts: 65
<?xml version="1.0" encoding="UTF-8" ?>
- <web-app>
- <servlet>
<servlet-name>FirstEL</servlet-name>
<servlet-class>it.sella.kathir.Control.SimpleServelt</servlet-class>
</servlet>
- <servlet-mapping>
<servlet-name>FirstEL</servlet-name>
<url-pattern>/FirstEL.do</url-pattern>
</servlet-mapping>
</web-app>
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

You didn't read the FAQ carefully. There's another link in it which tells you how to configure your web.xml. Chech how to configure web.xml for servlets 2.4 here.
[ June 25, 2008: Message edited by: Christophe Verre ]
Kathiresan Chinnasamy
Ranch Hand

Joined: Jan 01, 2008
Posts: 65
Hi Christophe Verre,

Thank you..i read the FAQ .. it is working now ..
Arpit Gadle
Ranch Hand

Joined: Dec 16, 2008
Posts: 69

Hello,
I am also facing the same problem.

I had declared the web-app as Servlet 2.5 and JSP 2.1 using Servlet 2.5 Schema

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>web app name here</display-name>

I am using Tomcat 6 and JSTL 1.1

What configuration I have to made in the deployment discriptor.

Also will you tell the reason for which the EL is disabled for JSP.

Regards,
Arpit
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 453

EL expressions are enabled by default but sometimes the container ignores them (vendor dependent ).

just use the page directive to enable them

<%@ page isELIgnored="false" %>

and it will work for sure

avi sinha


SCJP 5.0 SCWCD 5.0
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

but sometimes the container ignores them (vendor dependent )

Concerning enabling EL by default, I haven't heard of any container behaving strangely. You should not have to use the isELIgnored attribute of the page directive.

Arpit, can you show your full web.xml, and a jsp file which doesn't work ? By the way, what is the filename of your JSP file ?

Also, can you try with the following web.xml ?
Arpit Gadle
Ranch Hand

Joined: Dec 16, 2008
Posts: 69

Dear Christophe Verré,
I already followed your suggestion to go thrugh the "how toconfigure web.xml" given to Kathiresan Chinnasamy and also posted the same updated previously.

Here is code for your reference

easy.jsp


web.xml


And your were right there is no need to use isElIgnored atribute in page directive. Now the test jstl is working finr. I have tried this compatibility.
Case 1:
Tomcat 6.0(Servlet 2.5 and JSP 2.1) and was using JSTL 1.2

-- My web.xml was simple

<web-app>
</web-app>

and also removed the isElIgnored attribute

Then also the demo web-app is working.

Case2:
Using Tomcat6(servlet 2.5 and JSp 2.1) and using JSTL 1.1.2(jstl.jar and standard.jar)

Else everything was as in case 1 but it didn't worked out.

Then I added the isELIgnored in page directive and it worked.


Can you explain me the reason behind these. I think case 1 and case 2 are not the corect way for devloping a web-app. What you mentioned is the correct way to configure a web-app.

Regards,
Arpit
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to enable EL in a jsp page?