Solved

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

Posted on 2003-11-03
5
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

In this blog we highlight approaches to managed security as a service.  We also look into ConnectWise’s value in aiding MSPs’ security management and indicate why critical alerting is a necessary integration.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

717 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