• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2179
  • Last Modified:

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.



0
ttlguk
Asked:
ttlguk
  • 10
  • 9
1 Solution
 
rrzCommented:
The easy way would be to use JSTL <c:import> tag.  What is your web app server ? Is it  Tomcat ?  
0
 
rrzCommented:
If you don't want to use JSTL then you could use HttpURLConnection.
0
 
ttlgukAuthor Commented:
Web server is JBOSS.

plz advise.

Thanks.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
rrzCommented:
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
0
 
ttlgukAuthor Commented:
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.
0
 
ttlgukAuthor Commented:
Hie rrz,

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

Thanks.
0
 
rrzCommented:
Yes, those two.
0
 
ttlgukAuthor Commented:
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.
0
 
rrzCommented:
>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.
0
 
ttlgukAuthor Commented:
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">
0
 
ttlgukAuthor Commented:
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.
0
 
rrzCommented:
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
0
 
ttlgukAuthor Commented:
thanks rzz ..

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

Gd nite ...
0
 
rrzCommented:
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" %>
0
 
ttlgukAuthor Commented:
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.
0
 
rrzCommented:
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.
0
 
ttlgukAuthor Commented:
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.
0
 
rrzCommented:
I'm glad you have JSTL installed now. Sorry again for the bad advice. I have using Tomcat 5.5 and JSTL 1.1  for so long I forgot how to use the previous versions.  I don't have Tomcat 4 on my system and can not reproduce your latest error.  JSTL is suppose to be easy so I suggest using the full URL instead of getting into configuration modifications. Just try something like  
<c:import url="http://localhost:8080/importExport/import/test.jsp"/>
   
If you do want to add   crossContext="true" you must create a context element in your Tomcat's server.xml file located in  Tomcat/conf as described at
http://tomcat.apache.org/tomcat-4.1-doc/config/context.html 
Just look in the <Host> element  and locate a <context>  that is already there. Yours will go along side of it. Look at  
http://www.onjava.com/pub/a/onjava/2003/06/25/tomcat_tips.html   
http://www.akadia.com/download/soug/tomcat/html/tomcat_server_xml.html
 Something like  
<Context path="/yourContext1"  docBase="${catalina.home}/webapps/yourContext1"
         crossContext="true">
</Context>
or
<Context path="/yourContext1"  docBase="/webapps/yourContext1"
         crossContext="true">
</Context>
or
<Context path="/yourContext1"  docBase="yourContext1"
         crossContext="true">
</Context>

Finally if all the above doesn't work for you then  use code from bloodredsun  
     /**
      * Simple connection method using HttpUrlConnection to send a GET
      * request to the location specified by the URL parameter.
      * @param pURL
      * @return String
      */
     public static String getURLContent(final String pURL) {
          //setConnectionTimeout() ;
          StringBuffer sb = new StringBuffer();
          try {
               URL u = new URL(pURL);
               HttpURLConnection huc = (HttpURLConnection)u.openConnection();
               huc.setRequestMethod("GET" );
               huc.connect();
               BufferedReader br = new BufferedReader(new InputStreamReader(huc.getInputStream()));
               int b = 0; //read in the HTML returned
               while ((b = br.read()) != -1) {
                    sb.append((char)b);
               }
               //close reader
               br.close();
               //disconnect connection
               huc.disconnect();
          } catch (IOException e) {
               System.out.println( "Unable to open connection: " + e.getMessage());          
               return "" ;
          } //end try/catch
          return sb.toString();
     } //end getURL method
0
 
ttlgukAuthor Commented:
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.

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 10
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now