Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

JSP EL not working

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have written a simple jsp custom application.
I am getting the value of username when i use scripting but not getting the value of username when i try this ${username} in my JSP.
I am using tomcat 5.0 and jstl (jakarta-taglibs-standard-1.1.2).
Please let me know where i am going wrong.
Thanks in advance.
Following are my files in the webapp:

HelloTag.jsp
------------
<%@ page language="java" contentType="text/html" %>
<%@ taglib uri="WEB-INF/lib/mytags.tld" prefix="mytag" %>

<html>
<head><title>Custom Tag Demo</title></head>
<body>
<form name="myform" method="post">
username:<input type="text" name="username">
<input type="submit">
</form>
Here is custom content: <mytag:hello user="${username}"/>
</body>
</html>

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

<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0">

<tlib-version>1.0</tlib-version>
<short-name>mytagslib</short-name>
<uri>randomThings</uri>
<tag>
<description>My Custom Tags Library</description>
<name>hello</name>
<tag-class>mytags.HelloTag</tag-class>
<body-content>empty</body-content>
<attribute>
<name>user</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>

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 xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<servlet>
<servlet-name>HelloTag</servlet-name>
<servlet-class>mytags.HelloTag</servlet-class>
</servlet>

<taglib>
<taglib-uri>randomThings</taglib-uri>
<taglib-location>WEB-INF/lib/mytags.tld</taglib-location>
</taglib>

</web-app>

HelloTag.java
-------------
package mytags;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;
public class HelloTag extends TagSupport
{
public String user;
public void setUser(String user) {
this.user = user;
}
public int doStartTag()
{
try
{
JspWriter out = pageContext.getOut();
out.print("Hello from custom tag!");
out.print("Hello" + user + "<br>");
}
catch (IOException err)
{
System.out.println("Error:" + err);
}
return (SKIP_BODY);
}
}
 
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Web.xml you have is pointing to 2.3.dtd.
Try changing to 2.4 spec

like this
 
Sheriff
Posts: 67651
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You are using both the 2.3 DOCTYPE and the 2.4 schema declaration. Use only one: the 2.4 schema.
[ June 14, 2008: Message edited by: Bear Bibeault ]
reply
    Bookmark Topic Watch Topic
  • New Topic