Solved

Adding <taglib> to web.xml

Posted on 2007-04-07
7
6,113 Views
Last Modified: 2013-11-24
Hi, Im using Intellij IDEA and working through a JSTL book. When I try and add the <taglib> directive to my web.xml file to reference the jstl tags, Intellij highlights the directive as being invalid for web.xml.

I dont understand why the book says ive to add the taglib tag, but intellj wont let me do it?!?!
0
Comment
Question by:colr__
7 Comments
 
LVL 11

Expert Comment

by:Manish
ID: 18869636
can you post the web.xml?
0
 
LVL 10

Expert Comment

by:Jaax
ID: 18869683
Ensure that this is how the taglib is defined

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

Also ensure that the taglib tag appears in the order specified below

<!ELEMENT web-app (icon?, display-name?, description?, distributable?,
context-param*, filter*, filter-mapping*, listener*, servlet*,
servlet-mapping*, session-config?, mime-mapping*, welcome-file-list?,
error-page*, taglib*, resource-env-ref*, resource-ref*, security-constraint*,
login-config?, security-role*, env-entry*, ejb-ref*,  ejb-local-ref*)>

Some of the tags are not mandatory. What is important to maintain the order of the tags
0
 
LVL 27

Expert Comment

by:rrz
ID: 18869743
>I dont understand why the book says ive to add the taglib tag, but intellj wont let me do it?!?!  
Is it an old book ? Does it describe JSTL 1.0 ?    If you are using JSTL 1.1(and JSP 2.0) then the TLD's are in the jars. There is no need to add anything to your web.xml in order to use JSTL 1.1  .  Just put the jars in your classpath. If you are using Tomcat 6  put the jars in  <TomcatHome>/lib. If you are using Tomcat 5 then put them in <TomcatHome>/common/lib.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 8

Author Comment

by:colr__
ID: 18869938
rrz@871311 - yeh, im using 1.0 jstl, following what the book is using, although im also using tomcat 5. So I need to add the tld files. Although I can use 1.1 jstl, Id rather work with what the book is using for the timebeing.

Jaax - I copied your example, and checked the ordering but intellij is still highlighting it in red, with a comment 'element taglib is not allowed here'. Ive listed my web.xml below - perhaps im using the wrong DTD? It was auto-generated by Intellij.

--------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
         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" >

    <servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        <init-param>
            <param-name>config</param-name>
            <param-value>/WEB-INF/struts-config.xml</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <taglib>
        <taglib-uri>mytags</taglib-uri>
        <taglib-location>/WEB-INF/taglib.tld</taglib-location>
    </taglib>
</web-app>
--------------------------------
0
 
LVL 27

Accepted Solution

by:
rrz earned 500 total points
ID: 18869990
I don't really know if you can use JSTL 1.0 with Tomcat 5. But you might try using this.
<!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>
your tags here in the proper order as posted by Jaax above
</web-app>

Since you are using Tomcat 5, you should really use JSTL 1.1.2  and stay with the root tag you posted in your web.xml.
 In Servlet 2.4  the order of elements in your web.xml does not matter.
0
 
LVL 8

Author Comment

by:colr__
ID: 18870245
rrz@871311 - changed the dtd and it sorted the problem. Im obviously not using the most up to date versions, but I I would rather stick to to the book for the timebeing then look at the new develoments once Ive got that sorted.

Thanks for the help.
0
 
LVL 27

Expert Comment

by:rrz
ID: 18870744
Thanks for closing, but you should have split the points.  
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
bunnyEars challenge 6 118
java stored proc example 9 29
runtime exception 2 27
Unhandled exception type Exception 18 28
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now