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

How to enable EL in a jsp page?

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Make sure that you have written your web.xml correctly. Check this FAQ.
 
Kathiresan Chinnasamy
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<?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
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Christophe Verre,

Thank you..i read the FAQ .. it is working now ..
 
Ranch Hand
Posts: 69
MySQL Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 69
MySQL Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Curse your sudden but inevitable betrayal! And this tiny ad too!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic