Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6016377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:58:25+00:00 2026-05-23T02:58:25+00:00

I would like some help with something I have to implement. Thank you very

  • 0

I would like some help with something I have to implement. Thank you very much in advance.

I am doing a webapplication with struts2. Right now I need to implement a way trough which the user could obtain a xml file but without reloading the web page.

From the jsp, with jquery, I have implemented an ajax call (to an action) like this:

$(function() {
[...]
$("#getXML").click(function() {
        [...]
        $.ajax( {
            type : "POST",
            url : "Servlets.action",
            data : "id="+$id+"&objects="+$objectsMap+"&relations="+$linesMap+"&inputs="+$inputs+"&option=2",
            dataType : "xml",
            success : function(data) {
                        //¿??
                      }
        });
        });   });

I have defined the action Servlets in the struts.xml configuration.

And the action right now looks like this:

public class Servlets extends ActionSupport implements SessionAware, ServletRequestAware{

private ApplicationDao applicationDao;
public void setServletRequest(HttpServletRequest request) {
    this.request = request;
}

public String execute() throws Exception {
    [...]
    if (request.getParameter("option").equals("1")) {
        [...]
    }
    if (request.getParameter("option").equals("2")) {
        [...]
        File xml = new File(id+".xml");
        XMLcreator.createXML(id,project,xml);
        //I want to return the File object "xml" to the user through the jquery
    }
    else {
        return ERROR;
    }
    return SUCCESS;
}  }

I would like someone to tell me how can I return the File object “xml” to the user that has ordered it.

Thank you very much,

Aleix

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:58:26+00:00Added an answer on May 23, 2026 at 2:58 am

    First, I would encourage you to never “return ERROR”. A better approach is to just throw an exception and let the ExceptionMappingInterceptor map that to your error page.

    As for your problem, you want your Ajax action to return some XML. One way to do that is to expose the File object via a getFile() method and then create a JSP to display it (as XML).

    For example

    public class Servlets extends ActionSupport ... {
      private File file;
    
      public String execute() throws Exception {
        [...]
        if (request.getParameter("option").equals("2")) {
          [...]
          file = new File(id + ".xml");
          XMLcreator.createXML(id, project, file);
        } else {
          throw new RuntimeException("Your error message here.");
        }
        return SUCCESS;
      }
    
      public File getFile() {
        return file;
      }
    }
    

    Then, your JSP would look similar to this (not sure what your specific XML looks like):

    <?xml version="1.0" encoding="UTF-8"?>
    <%@ page contentType="text/xml;charset=UTF-8" language="java" %>
    <file hidden="${action.file.hidden}">
      <name>${action.file.name}</name>
    </file>
    

    ${action.file} refers to the getFile() method on your action.

    Then just make sure that the JSP is mapped to the SUCCESS result.

    Another way to handle this is to create a custom result type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Java servlet-based web applications. I would like to implement some operations in
I'm new to the site. would like some help if at all possible. I
I would like to as some help. Is there a certain method in javascript/jquery
Good morning! I would like to ask some help from you guys on how
I need some help figuring out how I should do this. I would like
I am working with an array and need some help. I would like to
I would like some of my preferences to have icons, like the Settings app.
I have a form which for some questions would ask if something was included
I would like to know if we have something in XSL 2.0, equivalent to
I would like some advice on the best approach to use in the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.