Solved

Getting an XML doc from a Struts Action class into a JSP

Posted on 2003-11-03
5
229 Views
Last Modified: 2010-04-01
Using Struts, I have this Action Class

    public static final String SESSION_USER_PROFILE = "USERPROFILE_SESSION_KEY";
    public static final String REQUEST_FORPARTYID = "forPartyId";
    public static final String REQUEST_ACTION_SUBMIT = "submit";
    public static final String FORWARD_SUCCESS = "success";
    public static final String FORWARD_SUCCESSXML = "SuccessXML";
    public static final String FORWARD_ERRORXML = "ErrorXML";
    public static final String REQUEST_ACCOUNTSXML = "accountsXML";

    public ActionForward process (ActionMapping actionMapping,
                                  ActionForm actionForm,
                                  HttpServletRequest httpServletRequest,
                                  HttpServletResponse httpServletResponse) {

        ActivityAccountsActionForm frm = (ActivityAccountsActionForm) actionForm;
        HttpSession session = httpServletRequest.getSession();
        UserProfile up = (UserProfile)session.getAttribute(SESSION_USER_PROFILE);

        ActivityMgmtHelper helper = new ActivityMgmtHelper();
        ActivityMgmtXml helperXml = new ActivityMgmtXml();

        int forPartyId = Integer.parseInt(httpServletRequest.getParameter(REQUEST_FORPARTYID));
        frm.setForPartyId(forPartyId);
        helper.requestActivityAccountData(frm, up);

        frm.setActivityAccountsXML(helperXml.getActivityAccountsXml(up, frm.getPortfolio()));
        session.setAttribute(REQUEST_ACCOUNTSXML, frm.getActivityAccountsXML());

            return actionMapping.findForward(FORWARD_SUCCESS);
        }

and this JSP

<%@ page language="java" %>
<%= session.getAttribute("accountsXML") %>


and I commonly use these tag libraries

<%@ taglib uri="/WEB-INF/tlds/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/tlds/struts-template.tld" prefix="template" %>
<%@ taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/tlds/fmt.tld" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/tlds/c.tld" prefix="c" %>




The problem:
frm.getActivityAccountsXML() returns an XML document that I use client-side. This document can be quite large (I've seen 600k and larger WILL happen).  I do not want to pass this big XML doc through the session (as above) or as a request attribute (which would be better than the session object, I know...).

I tried using c:out, but it freaking HTMLencodes the XML doc...needless to say, I get a parse error.

Points go to whomever can tell me how I get the XML doc from frm.getActivityAccountsXML() in the JSP without passing the value through the session or request objects, without HTMLencoding it, and using the tag libs above (or directly from the ActivityAccountsActionForm class) and using the struts model like seen above.


I'm too picky... ;-)
0
Comment
Question by:mgeiser
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
kotan earned 250 total points
ID: 9674861
In the Action, straight away output the buffer without go through jsp

   response.setContentType("text/xml");
   PrintWriter pw = response.getWriter();
   pw.print(frm.getActivityAccountsXML());

so the Action return null;
0
 
LVL 6

Expert Comment

by:kotan
ID: 9674881
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9675598
Don't you think you have too much open questions to post a new one?
>> I'm too picky... ;-)
me too ;-)
0
 

Author Comment

by:mgeiser
ID: 10858838
The points will go to Kotan for a great answer that I have used...

I'm surprised that no one mentioned <c:out value="${ActivityAccountsActionForm.activityAccountsXML}" escapeXml="false"/>



0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Find out what Office 365 Transport Rules are, how they work and their limitations managing Office 365 signatures.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now