[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Getting error in including JSP file into other JSP file in STRUTS Application??

Posted on 2006-05-06
16
Medium Priority
?
198 Views
Last Modified: 2010-04-01
Hi,

I have two jsp pages. MemberLogin.jsp & viewcart.jsp.
In memberLogin.jsp I want to include viewcart.jsp. I have one action class into my application as "viewcartAction.java" & corresponding formbean as "viecartForm.java" with action having forward value "viewcart" with scope request, which is forwarding to Viewcart.jsp. On Viewcart.jsp page I can display all values from formbean "viewcartform.java" when I am typing in browser as path "viewcart.do". But when I am trying to include this viewcart.jsp file into Memberlogin.jsp, I am getting followin error:-
=================================
javax.servlet.ServletException: Cannot find bean viewcartForm in any scope
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
org.apache.jsp.jsp.MemberLogin_jsp._jspService(org.apache.jsp.jsp.MemberLogin_jsp:556)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
===================================

How to solve this??
What I should do if I want to include viewcart.jsp(which is taking values from its own actioncalss & formbean) into MemberLogin.jsp??

Please tell me.

Thanx in advance.
Prash
0
Comment
Question by:Econify
  • 6
  • 5
  • 2
13 Comments
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 16620850
Can this solve your problem?

http://www.experts-exchange.com/Web/Web_Languages/JSP/Q_21530056.html

If no, please post your struts-config.xml and your both jsps.
0
 

Author Comment

by:Econify
ID: 16620896
Hi,
My struts config.xml is:-
========
   <action
      attribute="viewcartForm"
      input="/jsp/ViewCart.jsp"
      name="viewcartForm"
      path="/viewcart"
      scope="request"
      type="com.pal.struts.action.ViewcartAction"
      validate="false">
      <forward name="viewcartpage" path="/jsp/ViewCart.jsp" />
    </action>
=========
MemberLogin.jsp:-
============
----Struts-Tags declaration-----
<body>
----body part of memberLogin.jsp-------(Some html sentences)
      <%@ include file="ViewCart.jsp" %>  
----body part of memberLogin.jsp-------(Some html sentences)
</body>
</html>
===========
ViewCart.jsp:-
=======================
<table width="70%" bgcolor="#ffffff">
      <logic:empty name="viewcartForm" property="cartdata">
            <tr>
                  <td colspan="5">Your Shopping Cart is Empty!!!</td>
            </tr>
      </logic:empty>
      <logic:notEmpty name="viewcartForm" property="cartdata">
            <tr>
                  <td colspan='25' class=header width="100%" height=30>
                  <center><blink>Parts in your Shopping Cart </blink></center>
                  </td>
            </tr>
            <tr>
                  <td>
                  <table border="0" cellpadding="0" width="100%" bgcolor="#71B8FF"
                        bordercolor="#000000" cellspacing="1">
                        <tbody>
                        <tr>
                        <td class=aheader align=center>
                        Part No.
                        </td>
                        <td class=aheader align=center>
                        Description
                        </td>
                        <td class=aheader align=center>
                        Qty
                        </td>
                        <td class=aheader align=right>
                        Unit-Price($)
                        </td>
                        <td class=aheader align=right>
                        Sub-Total($)
                        </td>      
                        </tr>      
                              <logic:iterate name="viewcartForm" property="cartdata"
                                    id="partsincart">
                                    <tr>
                        <td class=cartevenrow><bean:write      name="partsincart" property="partid" /></td>
                        <td class=cartevenrow><bean:write      name="partsincart" property="partdesc" /></td>
                        <td class=cartevenrow><bean:write      name="partsincart" property="qty" /></td>
                        <td class=cartevenrow><bean:write      name="partsincart" property="unit_price" /></td>
                        <td class=cartevenrow><bean:write      name="partsincart" property="unit_price" /></td>
                        <td class=cartevenrow><bean:write      name="partsincart" property="rfqpart" /></td>
                                          <td class=cartevenrow>
                                          </td>                                          
                                    </tr>                                    
                                    <%
                                    }
                                    else
                                    {
                                    %>
                                    <tr>
                  <td class=cartoddrow><bean:write      name="partsincart" property="partid" /></td>
                  <td class=cartoddrow><bean:write      name="partsincart" property="partdesc" /></td>
                  <td class=cartoddrow><bean:write      name="partsincart" property="qty" /></td>
                  <td class=cartoddrow><bean:write      name="partsincart" property="unit_price" /></td>
                  <td class=cartoddrow><bean:write      name="partsincart" property="unit_price" /></td>
                  <td class=cartoddrow><bean:write      name="partsincart" property="rfqpart" /></td>
                  <td class=cartoddrow>
                                          </td>                                          
                                    </tr>                                                                        
                              </logic:iterate>
                  </table>
                  </td>
            </tr>
      </logic:notEmpty>
</table>
========================

In this I Just Want to display the content of iewCart.jsp into Memberlogin.jsp.

Please help me.
Thanx.
0
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 16620988
Hi,

Then how do you call MemberLogin.jsp? is there an action defined in struts-config.xml that calls this page?
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.

 

Author Comment

by:Econify
ID: 16621025
Hi,
Yes, there is action for calling memberLgin.jsp as follows:-
================
  <action path="/memberlogin" type="com.pal.struts.action.MemberloginAction">
      <forward name="memberlogin" path="/jsp/MemberLogin.jsp" />
    </action>
================

& When I am trying to view MemberLogin.jsp alone(without <% include...%> tag for Viewcart.jsp) I am able to see contents of MemberLogin.jsp.
Also When  am trying to view alone viewcart.jsp by using viewcart.do(URL) in browser I am able to see its contents.
But I want to view Contents of viewcart.jsp file into MemberLogin.jsp file.

How should I do that?

Thanx.

Prash
0
 
LVL 16

Accepted Solution

by:
Peter Kwan earned 1000 total points
ID: 16621060
You need to define in your action mapping for memberlogin as following:

 <action path="/memberlogin" type="com.pal.struts.action.MemberloginAction" attribute="viewcartForm"  name="viewcartForm"  scope="request">
      <forward name="memberlogin" path="/jsp/MemberLogin.jsp" />
    </action>
0
 

Author Comment

by:Econify
ID: 16642155
Hi,
Thanx for your reply.
I tried with the above way as u told. (defining action mapping). Now I am able to see the some parts of the viewcart.jsp on my MemberLogin.jsp.
I can now only see the header parts of table from my viewcart.jsp in my "MemberLogin.jsp" & I cant see any data into table. The table gets displayed blank(only getting table row headers on page) like follow:-
------------------------------------------------------------------------------------|
part no | Desc | .................................................................................|
------------------------------------------------------------------------------------|

& no data gets displayed below Table headers.
Instead of <%@ include file....%> tag , I tried with <jsp:include> also. but no change in result.
What extra thing needed to do here?

PLs tell me.

Thanx
Prash
0
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 16644929
In your MemberloginAction class, you need to set the data into your viewcartForm form bean object, just like you did in your ViewcartAction.

Or another way is to make your MemberloginAction class extends the ViewcartAction class
0
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 16644958
and call your super method to populate data to your viewcartForm form bean object
0
 

Author Comment

by:Econify
ID: 16677780
Hi,
Sorry for my late response.
Actually I want the viewcart.jsp notonly included in MemberLogin.jsp page but also there are other 5-6 page page in my application in which I want to display this viewcart.jsp (which containd ViewcartForm beans). So If I will follow your above method of setting data into viewcartForm object into action calss "MemberLoginAction" then I have to do same for all my other 5-6 action calsses corresponding to other JSP pages into which I want to include this viewcart.jsp.
So is there any method that I can call implicite "viewcart.do" which will populate "vaewcartForm beans" objects & then I can include it into my response body (eg:- body of member login.jsp)
I tried with includeaction as follows:-
===============

   <action  
      attribute="viewcartForm"
      input="/jsp/ViewCart.jsp"
      name="viewcartForm" path="/viewcart"
      scope="request"
      type="org.apache.struts.actions.IncludeAction"
      validate="false">
      <forward name="viewcartpage" path="/jsp/ViewCart.jsp" />
    </action>

<action path="/memberlogin" type="com.pal.struts.action.MemberloginAction"
scope="request">
      <forward name="memberlogin" path="/jsp/MemberLogin.jsp" />
    </action>    
===============
& then I tried following code in my MemberLogin.jsp
==============================
<jsp:include page="/viewcart.do" />
===============================

But Still I am not able to access the contents of my Viewcart.jsp into MemberLogin.jsp.

Pls tell me if I can do it with using "Includeaction" type? If yes then how?
Or is there any other method to do so?

Thanx
Prash
0
 
LVL 5

Assisted Solution

by:jpolin1
jpolin1 earned 1000 total points
ID: 16689742
You should move the objects in the viewCartForm up to a new "BaseForm" and have all of your other forms inherit from this base form. You could use a base action to populate the objects on the base form.  You can use this approach for objects that are used across the entire application.
0
 

Author Comment

by:Econify
ID: 16690186
Hi,
Is there no any straightforward methhod?
We Can't do this with action of type "org.apache.struts.Includeaction" or by using <jsp:include> tag???

Thanx.
Prash
0
 
LVL 5

Expert Comment

by:jpolin1
ID: 16690198
I am not familar with the IncludeAction type, including a jsp with the jsp include won't work b/c the action mapping creates the form. I've never seen someone include an actual mapping(*.do) with a jsp:include tag.
0
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 16690564
You can't have a *.do in your jsp:include tag. Therefore the most appropriate way is to do that what I (and jpolin1) suggests.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
LinkedIn blogging is great for networking, building up an audience, and expanding your influence as well. However, if you want to achieve these results, you need to work really hard to make your post worth liking and sharing. Here are 4 tips that ca…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question