How to share JSP pages in more then one project? - spring

I am trying to find a way to share JSP pages in more then one page?
Example we have the following projects:
commmon
projectA
projectB
The common project has all the CSS, images and two JSP pages. header.jsp and footer.jsp which all the projects in my firm is going to use.
We try adding:
<jsp:include page="/common/webapphead.jsp" />
to projectA and projectB but it still cant find the header, But if I goto
http://127.0.0.1:8080/common/webapphead.jsp
The page does display.

An easy way is to use JSTL. Use the c:import tag.
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:import url="http://127.0.0.1:8080/common/webapphead.jsp" />
Alternatively if you can enable cross context access, then you could use
<c:import url="/webapphead.jsp" context="/common" />
Look at
http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Common_Attributes

Related

How do you include twitter bootstrap with spring mvc?

I have spring mvc supplied text boxes and buttons in form page how to include twitter bootstrap in those tags. Where do I place bootstrap related files in the folder structure and which jar do I required to use bootstrap?
Example text boxes are:
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<form:form method="post" commandName="stdcmd">
username:<form:form path="txtUname">
password:<form:form path="txtPwd">
<input type="submit" value="register"/>
</form:form>
To use the bootstrap, you need to place the bootstrap files in the web folder. For example, resources/bootstrap folder. Then add the link to those files in jsp like:
<link rel='stylesheet' href='resources/bootstrap/bootstrap.min.css'>
<script type="text/javascript" src="resources/bootstrap/bootstrap.min.js"></script>
Also on your spring config file include this one:
<mvc:resources mapping="/resources/**" location="/resources/bootstrap
Check this link for more info
You should be able to access the classes from bootstrap and apply in your jsp.

Spring taglib in uiBinder xml-file

How can I put my taglib prefix correctly in my name.ui.xml file, is it even possible ?
In an html/jsp file it normally would work with
<%#taglib uri="http://www.springframework.org/tags" prefix="spring"%>
But thats not the case with uiBinder xml files. Is there a way or an alternative ? I'm trying to ensure multilingualism in my application. Thx for any help :)
You do understand that JSP is processed by your server, and UiBinder is processed by the GWT compiler to produce JS for the browser (client), right?
If you want to internationalize your GWT application, there are tools for that: http://www.gwtproject.org/doc/latest/doc/latest/DevGuideI18n.html

Spring tags and facelets

Can I use Spring tags with facelets? I have one JSP page, and there is a directive:
<%# taglib prefix="s" uri="http://www.springframework.org/tags"%>
Then I can insert the tag <s:theme code='css' /> (I'm using theme resolver.) Now I need to use theme resolver in another project using facelets instead JSP. There is a namespace declaration instead the JSP directive, isn't?
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:em="http://java.sun.com/jsf/composite/emcomp"
xmlns:st="http://www.springframework.org/tags">
But in Eclipse the namespace is labeled with the warning marker and on server it does not work, because the tag library is missing, althought I have put the library Spring Web MVC in the lib directory of Eclipse Internal Glassfish server. The JAR really contains META-INF/spring.tld.
I'm unable to find, what's wrong.
No, unfortunately you cannot. Spring tags are based on a JSP taglib. Facelet taglibs are different from JSP taglibs. The reason you can use the old-fashioned jsp core tags (c:forEach etc) in facelets is because they have been ported to facelet taglibs. AFAIK, there has not been any port done yet of the Spring JSP taglib to a facelet taglib.

how to configure and use jstl in websphere

Does anybody know how to configure jstl in websphere. i know that we have use taglib directive in web.xml . where do i find web.xml in websphere 5.1.2 and how to add the configuration.
You don't need to modify web.xml at all. Some poor online tutorials indeed suggests that, but you must never take everything at the interwebs for serious. Especially not roseindia.net and consorts.
To install JSTL, all you basically need to do are the following two steps:
Download this file, unzip, browse to /lib and put both jstl.jar and standard.jar in the webapp's runtime classpath.
Declare any of the taglibs as per the JSTL documentation in top of JSP file. For example JSTL core:
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
That's all. The default webapp's runtime classpath covers under each Webapp/WEB-INF/lib folder. Just drop the JAR's in there.

Jasper in Jetty 6 throws exception for JSTL tag

I'm trying to run an application in jetty that runs fine in Tomcat 5.5. The app uses servlet 2.4 and JSP 2.0.
Jetty/Jasper is throwing this exception:
org.apache.jasper.JasperException: /WEB-INF/tiles/layout/main.jsp(85,55) PWC6340: According to the TLD, rtexprvalue is true, and deferred-value is specified for the attribute items of the tag handler org.apache.taglibs.standard.tag.rt.core.ForTokensTag, but the argument for the setter method is not a java.lang.Object
One odd thing, I can't find the TLD anywhere. It seems to be obtaining it by magic that I don't understand. Is it possibly getting a wrong TLD?
It's also hard to tell from where it's loading org.apache.taglibs.standard.tag.rt.core.ForTokensTag. Eclipse doesn't find it in the load path of the project.
Any hints welcome ...
Jetty includes their own JSTL library and there is no need to include jakrta taglib's standard and core jars.
If you do put jakartat taglib's jars into your web application then there is a conflict in the forTokens tag that causes this error while other tags work well. I suggest either remove the jakarta taglib implementation from your web app and rely on Jetty's, or stop using forTokens.
#Guss is correct, the only way out seems to be to avoid the use of c:forTokens.
example alternative to c:forTokens using c:forEach:
<%#taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%#taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:forTokens items="${input}" delims="," var="i">
<!-- do stuff with ${i} -->
</c:forTokens>
<c:forEach items="${fn:split(input,',')}" var="i">
<!-- do stuff with ${i} -->
</c:forEach>

Resources