Link to home
Start Free TrialLog in
Avatar of ttlguk
ttlguk

asked on

jsp include cross-context

Hi guys,

I am facing problem in switcing context.

Context 1:
--------------
JSP Page: callPage.jsp

<%@ taglib uri="/WEB-INF/b2b-jspTagLib.tld" prefix="ppjsp" %>
....
<ppjsp:listTemplateTaglib type_imp_exp="1" ownerOrgId="<%=orgId%>" userId="<%=userId%>" moduleId="1" includePage="../import/resultPage.jsp" ></ppjsp:listTemplateTaglib>

Context 2:
-------------
JSP Page: resultPage.jsp

My servlet (inside context 2):
--------------
public int doStartTag() throws javax.servlet.jsp.JspTagException{        
      try{
                   ListAttributeModel model = new ListAttributeModel();
            
                   model.setIncludePage(includePage);
                   model.setUserId(userId);
                   model.setModuleId(moduleId);
                  model.setOwnerOrgId(ownerOrgId);
                              
                   pageContext.setAttribute("ListAttributeModel", model,PageContext.SESSION_SCOPE);
                   pageContext.getPage();       
                   pageContext.include(model.getIncludePage());
                                      
                  StringBuffer sb = new StringBuffer();
                  sb.append("");
                  pageContext.getOut().write(sb.toString());
            }        
            catch(java.io.IOException e){            
                  throw new JspTagException("IO Error: " + e.getMessage());        
            } catch (ServletException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }        
            return EVAL_PAGE;    
      }

ERROR: File not found.
Context still remain "context 1". I want it change to "context 2" so that resultPage.jsp able to display in callPage.jsp.

Please advise.

Thanks.



Avatar of rrz
rrz
Flag of United States of America image

The easy way would be to use JSTL <c:import> tag.  What is your web app server ? Is it  Tomcat ?  
If you don't want to use JSTL then you could use HttpURLConnection.
Avatar of ttlguk
ttlguk

ASKER

Web server is JBOSS.

plz advise.

Thanks.
I don't use JBOSS. But I still think you should download JSTL from  
http://jakarta.apache.org/site/downloads/downloads_taglibs-standard.cgi   
and put the two jars  in your classpath. Try to use  
<c:import url="/directory/resultPage.jsp" context="/context2"/>

But I have a concern. Your resultPage.jsp is coded like a custom tag. Why is that ?     rrz
Avatar of ttlguk

ASKER

my result page contains a table. this page will retrieve data from db and display. I din't code like a custom tag, it is just normal jsp page.
Avatar of ttlguk

ASKER

Hie rrz,

What are the 2 jars you mentioned? are they jstl.jsr and standard.jar?

Thanks.
Yes, those two.
Avatar of ttlguk

ASKER

Hie rrz,

I already add these two. And, how about *.tld file? I added c.tld and modified web xml.

In the jsp page, I wrote:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<c:import url="/import/importDocument.jsp?type_imp_exp=1&ownerOrgId=<%=orgId%>&userId=<%=userId%>&moduleId=1" context="/importExport"/>

But, I got the error as below:

 org.apache.jasper.JasperException: XML parsing error on file /WEB-INF/c.tld: (line 3, col -1): Element type "taglib" is not declared.

What should I do? Anything wrong?

Please advise.

Thanks.
>I added c.tld and modified web xml.  
No, don't do that. The  tlds are in the jstl.jar and you don't have to worry about them. Change your web.xml back.
Avatar of ttlguk

ASKER

line 3 is this statement:

<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
    version="2.0">
Avatar of ttlguk

ASKER

oh .. already edited back.

i copied these 2 jar files into C:\JBoss-2.4.4_Tomcat-4.0.1\jboss\lib\ext folder.

JSP PAGE:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<c:import url="/import/importDocument.jsp?type_imp_exp=1&ownerOrgId=<%=orgId%>&userId=<%=userId%>&moduleId=1" context="/importExport"/>

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ERROR:
------------
org.apache.jasper.JasperException: This absolute uri (http://java.sun.com/jsp/jstl/core) cannot be resolved in either web.xml or the jar files deployed with this application

What is the problem?

plz advise.

thanks.
I don't use JBoss, so I don't know.
>C:\JBoss-2.4.4_Tomcat-4.0.1\jboss\lib\ext folder.  
Is that in the classpath for your contexts ?  
All I know is that in Tomcat we put them into  C:\Tomcat\common\lib   but you should ask someone that knows JBoss. I am going to bed now.  Good night.   rrz
Avatar of ttlguk

ASKER

thanks rzz ..

>C:\JBoss-2.4.4_Tomcat-4.0.1\jboss\lib\ext folder.  
yes .. this is our classpath.

Gd nite ...
Sorry my mistake.  For Tomcat 4  you must use  JSTL 1.0  .
http://jakarta.apache.org/site/downloads/downloads_taglibs-standard-1.0.cgi 
and use  
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
Avatar of ttlguk

ASKER

hi there,

Already downloaded the JSTL 1.0 and copy them to the classpath. But, I stil got the error ...

 " org.apache.jasper.JasperException: This absolute uri (http://java.sun.com/jstl/core) cannot be resolved in either web.xml or the jar files deployed with this application "



please advise.
I am sorry again. I have been  using version so long I forgot how to install 1.0  I see
http://www.developer.com/java/ejb/article.php/1447551   
that you were right to  install tlds and modify  your web.xml.  If that doesn't work then we will have to use  HttpURLConnection.
Avatar of ttlguk

ASKER

hi experts,

I have installed 1.0 successfully. However, I failed to include the following attribute crossContext="true"   in my application's Tomcat Context element. I am not sure where should I include. So i got this error :

javax.servlet.jsp.JspTagException: Unable to get RequestDispatcher for Context: "/importExport" and URL: "/import/test.jsp". Verify values and/or enable cross context access.

JBOSS version: JBoss-2.4.4
TOMCAT version : 4.0.1

please advise.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of rrz
rrz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ttlguk

ASKER

Hi rzz,

thanks... the problem is solved.

but, i stil have some problems e.g. the imported page css is not connected to its own context and caused the page not display properly. -_-''

Thanks again.