Setting file paths in eclipse projects? - java

In my JSP and servlets web app, I have this line in a TLD or XML file in eclipse - <%# taglib prefix="mine" uri="DiceFunctions"%> It gives me the error - Eclispe can not find
the tag library descriptor for "../DiceFunctions"
I know this has something to do with the path uri="DiceFunctions" in the above code.
How do I resolve this error ?
My project sturcture -

Have you create a taglib named 'mine' ?
you should read some doc about jsp taglib ;
The uri="DiceFunctions" is your taglib`s path

Related

JSP 2 tag files “/WEB-INF/tags” not found

Yes, this question is very similar to this one but with the huge difference that I am working with a TLD file rather than a taglib-to-folder declaration.
Okay, my setup is the following: I am migrating a pure-Java tag library to almost-JSP (some tags will still survive their Java form). I had a TLD defined under my classpath:META-INF folder. Some tags are defined as classes, while others are now defined as JSP 2 tag files under /WEB-INF/tags. Example given:
<tag-file>
<name>navbar</name>
<path>/WEB-INF/tags/navbar.tag</path>
<display-name>Navbar</display-name>
</tag-file>
This all works great under Eclipse, though I had to manually set up Web Deployment Assembly from src/META-INF to WEB-INF, otherwise the TLD file won't be recognized by Tomcat.
After happily debugging the code I have tried to create a WAR version of my application to be deployed to SIT. Despite the presence of the tags directory under WEB-INF along with the JSP 2 tag files, I am still unable to run the application.
And the error iiiiiiiiiiiiis:
org.apache.jasper.JasperException: /login.jsp (line: 3, column: 0) File [/WEB-INF/tags/navbar.tag] not found
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:41)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:275)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:91)
org.apache.jasper.compiler.Parser.processIncludeDirective(Parser.java:335)
org.apache.jasper.compiler.Parser.parseIncludeDirective(Parser.java:368)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:471)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1435)
org.apache.jasper.compiler.Parser.parse(Parser.java:139)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:227)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:100)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:199)
org.apache.jasper.compiler.Compiler.__compile(Compiler.java:356)
org.apache.jasper.compiler.Compiler.compile(Compiler.java)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:336)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:323)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:585)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:363)
org.apache.jasper.servlet.JspServlet._serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
The TLD is declared as usual
<%# taglib prefix="example" uri="http://www.example.org/example.tld"%>
How can I fix this?
Ok, I found the partial solution (I will update this answer if and when I find the complete one).
It looks like that if I deploy the TLD file under classpath, then I should deploy the tags accordingly.
I had to replace <path>/WEB-INF/tags/navbar.tag</path> with <path>/META-INF/tags/navbar.tag</path> and move all the tags under classpath:META-INF/tags.
This way, the WAR package is working.
Unfortunately, I broke my Eclipse setup, so the workaround was to manually setup a Deployment assembly entry from src/META-INF/tags to META-INF/tags because the tag file now references META-INF folder. Pretty ugly, but suitable for development at the moment.
I've had a similar experience. My project uses tags to keep navigation menus in a single place and use them on many jsp pages. I am using Tomcat 8. Some of the things I have learned along the way are:
The tags directory contains *.tld and *.tag files you are creating.
My configuration is Tomcat 8,Java 7,JEE 6,Servlet 3.1 and JSP 2.2. I am using a plain eclipse jsp project. (no maven) Here is my tld file:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE xml>
<taglib version="2.0" xmlns="http://java.sun.com/xml/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<tlib-version>1.2.5</tlib-version>
<jsp-version>2.2</jsp-version>
<short-name>taglibs</short-name>
<description>jsp tag library for the navigation code</description>
<tag>
<name>navMenu</name>
<tag-class>ksServer.navTag</tag-class>
<body-content>tagdependent</body-content>
</tag>
</taglib>
The beginning lines of a typical webapp jsp file are
<%# page language="java" contentType="text/html" pageEncoding="UTF-8" %>
<%# page import="ksClasses.KsvrmSqlAgent" %>
<%# page import="org.slf4j.Logger" %>
<%# page import="org.slf4j.LoggerFactory" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%# taglib prefix="kr" tagdir="/WEB-INF/tags" %>

Issue with uri of custom tag library

I have seen a weird problem while using custom tag libraries.
In one of my jsp pages the relative uri path of the custom tld file is wrong.
Taglib is included in jsp page like below
<%# taglib prefix="aaa" uri="WEB-INF/bbb.tld" %>
Location of bbb.tld is : Stores\WebContent\WEB-INF\bbb.tld
This taglib is included in a parent jsp file, and not there jsp file is imported/included from parent.
My application has several other jsp files, where the same taglib is used with the correct path.
The same code is deployed in multiple test environments. In a few environments the code is throwing an error of "Failed to find resource", which is expected. But the taglib is working fine in most of the environments, instead of wrong path.
Why is there discrepancy in the behavior between different server environments? Does the server automatically look for all tld files if the uri can't be resolved?
I would recommend adding a trailing slash ('/') before WEB-INF. Could you try the following?
<%# taglib prefix="aaa" uri="/WEB-INF/bbb.tld" %>
Hopefully, this will give you consistent results across all you server instances. Also, having your TLD in Stores\WebContent\WEB-INF\bbb.tld seems to be related to be using an IDE (e.g. Eclipse) to develop your application. Once you export your application as an EAR or WAR the path will look more like Stores.war/WEB-INF/bbb.tld

JSTL Taglib -error

i have the following pice of code:
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
If i want to run the programm i get the following error message:
HTTP Status 500 - The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
My JAR Files are in the WEB-INF/lib/ folder
--->javax.servlet.jsp.jstl-1.2.1-javadoc.jar (IMP)
--->javax.servlet.jsp.jstl-api-1.2.1-javadoc.jar (API)
I use the WEB.xml Version 3.0
So please can someone help me?!
Thanks
It seems you have added the javadoc of the JSTL instead of the code. Try downloading this one and add it to your lib directory:
http://mvnrepository.com/artifact/javax.servlet/jstl/1.2

Liferay Taglib import not working in JSP

I'm having trouble importing the liferay taglibs in one of my JSP pages, no idea what I'm doing wrong. I did the exact same thing in previous projects, but now for some reason it's not working.
My code to import:
<%# taglib uri="http://liferay.com/tld.ui" prefix="liferay-ui" %>
The syntax error I'm getting:
The absolute uri: http://liferay.com/tld.ui cannot be resolved in either web.xml or the jar files deployed with this application
I tried to google this problem quite extensively, but to no avail. The horrible documentation (or lack thereof) for liferay is also not a big help at all.
Thanks in advance for any help!
The taglib URI gets resolved from the following places(in the order):
If the container is Java EE platform compliant, the tag libraries that are part of the Java EE platform. This currently includes JSTL and JSF Tag Library libraries.
Taglib Map in web.xml, the web.xml can include an explicit map of URI's and TLD's respource paths.
TLDs in JAR files in WEB-INF/lib and TLDs under WEB-INF
TLD's supported by Container
In you case, check the following cases:
1) If jar file realted to liferay exists in WEB-INF/lib containing a TLD in jar/META-INF which will be defined with http://liferay.com/tld.ui URI.
2) If there is not jar file and the liferay-ui.tld exists outside the jar file, add the URI mapping entrey in your web.xml like below:
<taglib>
<taglib-uri>http://liferay.com/tld/ui</taglib-uri>
<taglib-location>/WEB-INF/tld/liferay-ui.tld</taglib-location>
</taglib>
it is not
<%# taglib uri="http://liferay.com/tld.ui" prefix="liferay-ui" %>
it should be
<%# taglib prefix="liferay-ui" uri="http://liferay.com/tld/ui" %>
notice that "tld.ui" must be "tld/ui".
liferay-ui.tld comes from util-taglib.jar that liferay adds to your WEB-INF/lib during hot deploy.
No entries to your web.xml are needed.
You probably need to include taglib declaration in your web.xml.
<taglib>
<taglib-uri>http://liferay.com/tld/ui</taglib-uri>
<taglib-location>/WEB-INF/tld/liferay-ui.tld</taglib-location>
</taglib>

JSP Googlemaps taglib not found, where have I gone wrong?

I'm trying to add Google Maps onto my JSPs by using the Googlemaps taglib.
I've added this into my maven pom
<dependency>
<groupId>com.lamatek</groupId>
<artifactId>googlemaps</artifactId>
<version>0.98c</version>
<scope>provided<>/scope
</dependency>
This then included the googlemaps-0.98c library under my project libraries in NetBeans, I right clicked and selected Manually install artifact and located the googlemaps.jar file I had downloaded.
I've then added this into my taglibs file
<%#taglib prefix="googlemaps" uri="/WEB-INF/googlemaps" %>
And have then included this where I actually want to show a map on my jsp
<googlemaps:map id="map" width="250" height="300" version="2" type="STREET"
zoom="12">
<googlemaps:key domain="localhost" key="xxxx"/>
<googlemaps:point id="point1" address="74 Connors Lane" city="Elkton"
state="MD" zipcode="21921" country="US"/>
<googlemaps:marker id="marker1" point="point1"/>
</googlemaps:map>
But when I load up my application, I get the following error.
org.apache.jasper.JasperException: /jsp/dashboard.jsp(1,1) /jsp/common/taglibs.jsp(6,56) PWC6117: File "/WEB-INF/googlemaps" not found
root cause
org.apache.jasper.JasperException: /jsp/common/taglibs.jsp(6,56) PWC6117: File "/WEB-INF/googlemaps" not found
Have I missed something simple? I'm unable to spot what I've done wrong so far..
Generally when you do this:
<%#taglib prefix="googlemaps" uri="/WEB-INF/googlemaps" %>
You are basically trying to say "the folder /WEB-INF/googlemaps has a bunch of .tag files for use" - which you don't.
Just browsing the documentation confirms this - it says you should be using this (note the usage of the tld extension):
<%# taglib uri="/WEB-INF/googlemaps.tld" prefix="googlemaps" %>
Source: http://www.lamatek.com/GoogleMaps/documentation.jsp#installation
If you set scope to provided in your pom it is not included in the war file and the taglib will not be found. You should change the scope to compile or runtime.
The URI should not be /WEB-INF/googlemaps.tld. It should match the value in the <uri> tag in the googlemaps.tld.
Open up the googlemaps.jar, find the googlemaps.tld, and find the <uri> tag. That's the URI you need.
UPDATE:
I just downloaded the googlemaps.jar. I'm incorrect; the URI is indeed <uri>/WEB-INF/googlemaps.tld</uri>.
That suggests that you have to extract the googlemaps.tld file and put it under /WEB-INF in your web context, be it WAR or exploded.

Categories

Resources