tags:

views:

50

answers:

1

Hi,

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.

+2  A: 

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.

skaffman
Perfect, your suggestion works beautifully. You are right, I was thinking that import means "import". Thanks once again!
msharma
HI skaffman, I just have a follow up question. I realized that if war2 has.jsp files then my c:import works fine. However if I have .jspf file which just contain jsf then the rendered page spits out the contents of the jspf file rather than the html. Any idea what I am missing, is it some kind of mapping that allows .jspf to be rendered in html?
msharma