I have some .jspf files that are fragments which I include in a new .jsp file. The reason they are fragments is that they are reused across multiple jsps with some additional components.
My issue now is that I want to use these .jsps in 2 different .war files.
So I created a new .jar file which includes these jspf, now I am trying to deploy this jar so that I am then import it in my new jsp which is inside 1 of the 2 wars.
I am not able to deploy the jar succesfully in Jboss 4.2. I am using Eclipse ide.
Any ideas on this? If there is an alternate approach I would appreciate any ideas.
Thanks for this suggestion, I have followed this idea and deployed my war1 which contains my .jspf files.
So in my war2 on a jsp I do:
<c:import context="/sharedComponents" url="/easyPayNamePaymentOption.jspf" var="easyPayName"/>
<%# include file="easyPayNamePaymentOption.jspf" %>
However I am not able to render this page with the included fragment, I am not sure how to address the imported jspf. I ahve tried several different ways like:
<%# include file="/sharedComponents/easyPayNamePaymentOption.jspf" %>
and also using var name like:
<%# include file="#{easyPayName}" %>
However it keeps looking inside the current war. How can I tell it to include the newly imported fragment and display it?
Thanks in advance.
I can see what you're trying to do, but this isn't going to work with a JAR file. All JSP files (including JSPF) have to inside a WAR, not a JAR.
The simplest solution is to put copies of the JSPF files into each WAR that needs to use them. Assuming that you don't want to do this, then there is an alternative, called a cross-context WAR.
By default, JBoss allows its webapps to request resources from each other. For example, say webapp1 (context path /app1) wants to import JSPF /my.jspf from webapp2 (context path /app2). You can use JSTL to do this, from inside webapp1:
<c:import context="/app2" url="/my.jspf"/>
So if you were to create a "shared" WAR file containing your JSPF files, and deployed this to JBoss, then your other webapps could use the above technique to include the contents of the JSPFs into their own JSPs.
edit: I've read your updated question, and I don't understand why you added var="easyPayName" to the <c:import> tag. All that's doing is importing the contents of easyPayNamePaymentOption.jspf and storing it in a variable called easyPayName, which seems completely unnecessary.
I think perhaps you're associating <c:import> with a java import? If so, don't - they're completely different. <c:import> should really have been called <c:include>, because that's what it does.
Just keep it simple, remove the attribute, and just have
<c:import context="/sharedComponents" url="/easyPayNamePaymentOption.jspf"/>
That's all you need to do - it will include the content of easyPayNamePaymentOption.jspf directly in the JSP.
Related
This question already has an answer here:
How specify path to .JSP file for request.getRequestDispatcher()?
(1 answer)
Closed 6 years ago.
I have a servelet called RegisterUser mapped as /register this servelet includes a jsp file called register.jsp . here is the structure of the project :
inside the servelet this code cannot find the jsp file :
RequestDispatcher view = request.getRequestDispatcher(registerView);
and the content of registerView is :
private static final String registerView = "../web/WEB-INF/views/Register.jsp";
It worked fine on eclipse but when I switched to Intellij it shows that the file cannot be found .
Liferay has a somewhat strange layout for it's web-inf and html folders. In Eclipse I never really code path completion to work well in JSPs because it always looked at the wrong spot for files. In IntelliJ I just setup different facets that will help the IDE help me. Here is an example. I have a facet called WEB-INF. In Liferay, when you reference a file in WEB-INF (tagfiles are a GREAT example here) you do it like this:
<%# taglib prefix="showMore" tagdir="/WEB-INF/tags/wj/showmore" %>
The problem there is that by default, the IDE wants to autocomplete like this:
<%# taglib prefix="showMore" tagdir="/docroot/WEB-INF/tags/wj/showmore" %>
I simply made a web facet and said that when I type /WEB-INF I really want you to look at /docroot/WEB-INF. This small change saves me so much headache throughout the day. I also did the same thing with /html instead of /docroot/html.
You know how in eclipse when you go to an init.jsp file in the ext environment it always freaks about the init.jsp includes from portal because it can't find it? I once again used a web facet (called portal-web) and I linked / to /liferay/builds/4.3.x/portal-web/docroot. Now when I say:
<%# include file="/
right there it starts autocompleting. It lists out everything in both portal-web and ext-web for me, because I have access to both inside Liferay! Doing this then:
<%# include file="/html/common/init.jsp" %>
it's a problem, I can even click init.jsp and press ctrl (cmd) + b and it will jump me right into the init file in portal.
I tend to run IntelliJ with one "Module" and two "Content Roots". One content root is portal, the other is ext. The plus here is that the debugger knows about the portal source files, and I can easily jump between jsp files as well.
Resource Link:
Why I use IntelliJ instead of Eclipse?
My JSP instantiates a MovieDetails class. I am currently working using scripting to ensure everything is working fine, before I move to tags.
I am using Tomcat 8.0. Directory structure for MovieDetails.class: com/library/model/beans. A copy of the directory structure with the MovieDetails.class file is also placed under WEB-INF/lib (have tried putting a .jar for the file too)
In the JSP I have:
<%# page import="com.library.model.beans.*" %>
And later:
<%
MovieDetails movDet = (MovieDetails)request.getAttribute("MovieDetailsBean");
....
....
%>
I am getting:
java.lang.NoClassDefFoundError: com/library/model/beans/MovieDetails
Can anyone please tell me why the JSP can't find the class in spite of the class being in the /lib directory?
NoClassDefFoundError and ClassNotFoundException is two different exception
I'm working on a web project using java/ jsp/ servlets/ html/ css in eclipse tomcat, where everything is in the WebContent folder.
In my jsp files... When I try to include other jsp files (using a link like "/fileName.jsp" in jsp include directive) I can do that successfully.
But When I try to include image files (using a link like "/fileName.jpg" in the <img src=""> tag) nothing happens.
Nothing happens because instead of looking in the WebContent folder for image file it looks in the tomcat home directory, i.e.
Instead of looking at "http ://localhost:port/projectName/..." it looks at "http: //localhost:port/..."
Why does it look at the wrong location only with <img src=""> tags but not in <%# /> tag.
A workaround for this is that I start giving absolute paths "/projectName/..." However doing this means I'm hardcoding project name everywhere. This is what I do not want.
Don't include binary content in an ascii output. Why not just use the img tag? If you need to do something to produce a jpeg, I would use a Servlet.
Because the jsp-Links in the website are getting processed and the image links not. Either change the image path or develop an filter that changes the images'links.
Yes Templar, that could have been a way to solve my problem.
However, I simply changed the Context Root of my project from "Project Name" to "/" in Eclipse. This solved my problem.
I am trying to follow the tutorial for JSP Templates at:
http://java.sun.com/developer/technicalArticles/javaserverpages/jsp_templates/
I am struggling to understand the <%# taglib uri='/WEB-INF/tlds/template.tld' prefix='template' %> tag.
What is the template.tld file, where does this come from?
I have tried to download the Resourses file of source code but this just contains a src.jar file. How do I use this? I can't even open the file!?! How do I see the source code example?
It's in the jstl.jar. You need standard.jar and jstl.jar in your WEB-INF/lib for JSTL.
You can get what you need here:
http://tomcat.apache.org/taglibs/
Download the standard tag library and all its JARs; put them in your WEB-INF/lib directory.
A uri, a uniform resource identifier is not necessarily pointing to any existing resource. It is an identifier, compare with url which is a uniform resource locator which helps you locate something. In many XML contexts for instance, it simply declares a namespace.
Sometimes the uri does however point to a real resource that you can read to get more information.
In this case you are declaring a namespace template to use in your jsp code (such as <template:dosomething/>) - the uri matches a uri declaration for whatever is implementing your tag functionality and can be found inside a jar (jstl.jar or standard.jar, can't remember which).
I was wondering if it was possible to maintain a directory structure within the application folder in side webapps folder, i.e. I have created a folder called ITC357, which acts as my application folder which carries all my files, so the directory path is as follows:
C:/Program Files/Tomcat5/webapps/ITC357
I'm doing an assignment and I would like to deploy that ITC357 in a separate folder can I do this? if so how?
It is not clear what you are asking:
If you asking if it is possible to have directories inside C:/Program Files/Tomcat5/webapps/ITC357 then the answer is "Yes".
If you are asking if it is possible to put your webapps file in a separate directory then the answer is "Inadvisable". The tomcat framework looks for certain files within the webapps/<name> tree; e.g. a context.xml file, a web.xml file, classes / JARs, etc. You could code your servlet to look for other things in other places, but this causes various problems with deployment (and undeployment) and security.
If that doesn't cover it, please clarify your question.
If you are writing JSPs, then the URL of the JSP will include any subdirectories that you create. So if under ITC357 you create a subdirectory called "foo", and in that subdirectory you have a JSP called "bar.jsp", and your context name is "plugh", then the URL of that JSP will be "http://whateverserver.com/plugh/foo/bar.jsp".
If you are using servlets, then it is up to your code to decide what to do with any URLs passed to it. You could map "http://whateverserver.com/plugh/foo/twisty.do" to "c:/program files/tomcat5/webapps/ITC357/WEB-INF/classes/foo/twisty.class", or you could map it to someplace totally different. (I prefer to map to a package name that matches the URL unless there's good reason to do otherwise.)