I am running simple JSP pages (in a Spring 3.1 web app) decorated with sitemesh, but without including sitemesh-decorator.tld and sitemesh-page.tld explicitely in my project. It works.
Yet, I see sample projects explicitely including these files in a \WEB-INF\tld folder. Is this necessary? If yes what for?
For example, one project has a generic taglibs.jsp page imported in all pages. It includes:
...
<%# taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
...
For the records
There is not point into inserting:
<%# taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
in a JSP page to be processed by sitemesh. This include should only appear in decorator pages.
There is no need to include these .tld(s) into your applicataion \WEB-INF\tld. They can be loaded directly from sitemesh.jar/META-INF directory.
Related
I noticed that on JSF pages i can include templates in my xhtml page like
<ui:composition template="/WEB-INF/tmp/tmp.xhtml">
is there any alternative to this using JSP Pages+ Hibernate?
With plain JSP you can only reuse content with instructions like:
<%# include file="banner.jspf" %>
JSF facelets allow passing parameters to the facelet to do this with JSP you would need an additional framework like struts.
I understand that to use jstl on JSP, one need to include this taglib in the jsp:
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
However, I was wondering if there is a way to refer this item via localhost.
====
For example, I can use this jquery which I downloaded and placed in my resource folder
<script type="text/javascript"
src="${pageContext.request.contextPath}/js/lib/jquery.min.js"></script>
instead of referring jquery from http://ajax.googleapis.com
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
====
Question: is there a way to refer jstl from local folder, instead of look up at http://java.sun.com?
Asking this question is because my client wanted a web app hosted on local network and have no internet access. so, no external referencing.
p/s: please no chit-chat, just written solution.
p/s/s: please don't advise me to change my programming language, framework or upgrade my java version. It is a restriction for my work.
The URI is a Universal Resource Identifier, it is NOT a locator (URL) or src of file.
This means that the URI is used to uniquely identify each taglib in an internal registry of taglibs.
This URI is specified in *.tld files in jstl jar. You can check it extracting jar and goto jstl-1.2\META-INF
So you cannot change this URI. It is accessible even without internet.
I'm building a taglib with a few custom tags. Some of these require a bit of JavaScript to work properly. What would be the best way to add the JavaScript so that it's included in the taglib jar?
The most obvious approach to me would be to put it into the custom tags' doStartTag() method like this pageContext.getOut().print("<script>my js</script>");, which I don't like for 2 reasons: It looks absolutely horrible and it gets added every time the tag gets used on a page.
I'm looking for a solution that lets me keep the JavaScript in a separate .js file that rests somewhere in the taglib jar and gets included only once per page whenever a custom tag is used.
Is it possible to inherit taglibs or imports from parent JSPs in their "descendants"?
Let me show you an example
header.jsp
<%# page contentType="text/html" isELIgnored="false"
import="org.something.utils.Constants"%>
//some code, Constants class is available here
index.jsp
<jsp:include page="template/header.jsp" />
//Constants is not available, I get a JasperException: Unable to compile class for JSP
also the taglibs inheritance doesn't seem to work. So is there a way how to make this work?
Taglibs and imports are not inherited, and everything in a tag as well cannot be inherited or passed through pages (except for JspContext and request attributes).
You have two options here:
Make the import in every JSP you have.
Make the common classes and libraries Global ones, this depends on the IDE and the server you are running.
Edit
Defining JSP implicit includes:
For Netbeans http://docs.oracle.com/cd/E19575-01/819-3669/bnajl/index.html
A global tutorial http://sabahmyrsh.blogspot.com/2009/06/jsp-defining-implicit-includes.html
Is there any extended JSP taglib available? Basically, because of project constraints, we're using a home-grown framework and working with JSPs. We want a taglib that will help us work easily with html forms and form elements and provide some sort of binding. Something like struts html tablib. I'm not sure if we can use the struts taglib standalone?
The best solution I can provide for you is to use a retired tag library from jakarta.
It still works but it is no longer supported or maintained by them.
The link can be found here
The one you will be interested in is the "input" tag library which has tags for the following fields:
form
text
password
textarea
hidden
select
option
radio
checkbox
There should be no problem using Struts with appropriate JAR files in Web App lib folders (put all the Struts JARs in there)