struts开发实践—读写xml实例(下)

类别:Java 点击:0 评论:0 推荐:

 struts开发实践—读写xml实例(下)

继续代码实例:

/************PrintReadAction.java代码Begin****************************/

package test;

import org.apache.struts.action.*;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.ServletException;

import java.io.IOException;

/**

 * 读取print.xml的字段信息,供选择

 */

public class PrintReadAction extends Action {

  public ActionForward perform(ActionMapping mapping,ActionForm form,

    HttpServletRequest request,HttpServletResponse response)

      throws IOException,ServletException {

      ActionErrors errors = new ActionErrors();

      String[] ifPrint=null;

      String path=request.getRealPath("/")+"/WEB-INF/print.xml";

      try {

        ReadWritePrintXML readwrite=new ReadWritePrintXML();

        Collection colField = readwrite.readXMLFile(path);

        request.setAttribute(BeanNames.TABLEFIELD_LIST, colField);

        return mapping.findForward("success");

    }

    catch (Throwable e) {

      e.printStackTrace();

      ActionError error = new ActionError(e.getMessage());

      errors.add(ActionErrors.GLOBAL_ERROR, error);

 

    }

    saveErrors(request,errors);

    return new ActionForward(mapping.getInput());

    }

}

/************PrintReadAction.java代码End******************************/

/************PrintSetAction.java代码Begin*****************************/

package test;

import org.apache.struts.action.*;

import javax.servlet.http.*;

import javax.servlet.*;

import java.io.*;

import java.util.*;

/**

 * 打印字段设置回写print.xml文件

 */

public class PrintSetAction extends Action {

  public ActionForward perform(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response)

  throws ServletException, IOException{

   ActionErrors errors = new ActionErrors();

   String[] multiSelect=request.getParameterValues("multiSelect");

   ArrayList colField=null;

   String path=request.getRealPath("/")+"/WEB-INF/print.xml";

   try{

     ReadWritePrintXML readwrite = new ReadWritePrintXML();

     readwrite.initialXMLFile(path);

     readwrite.writeXMLFile(multiSelect,path);

     return null;

   }

   catch (Throwable e) {

     e.printStackTrace();

     ActionError error = new ActionError(e.getMessage());

     errors.add(ActionErrors.GLOBAL_ERROR, error);

   }

   saveErrors(request, errors);

   return new ActionForward(mapping.getInput());

 }

}

/****************PrintSetAction.java代码End******************************/

本文地址:http://com.8s8s.com/it/it16604.htm