Solved

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

Posted on 2003-11-03
5
232 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
org.apache.jasper.JasperException: using jstl in jsp embedded jetty 13 618
spring example errors 33 345
withoutString  challenge 40 201
Books that can get me started on JAVA 2 96
In this increasingly digital world, security hacks are no longer just a threat, but a reality. As we've witnessed with Target's big identity hack 2013, Heartbleed in 2015, and now Cloudbleed, companies and their leaders need to prepare for the unthi…
February 24, 2017 — On February 23, Travis Ormandy, a vulnerability researcher at Google, reported on Twitter (https://twitter.com/taviso/status/834900838837411840) that massive stores of data have been leaked by CloudFlare, a company that provide…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

825 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