Struts Development Practice - Read and write XML instances (below)

zhaozj2021-02-16  55

Struts Development Practice - Read and write XML instances (below)

Continue code example:

/***************************************************************************** /

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;

/ **

* Read the field information of Print.xml for selection

* /

Public class printreadaction extends action {

Public ActionForward Perform (ActionMApping Mapping, Actionform Form,

HTTPSERVLETREQUEST REQUEST, HTTPSERVLETRESPONSE RESPONSE

THROWS IOException, servletexception {

ActionerroS 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.setttribute (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 ());

}

}

/***************************************************************************** /

/*************************************************************************************** /

Package test;

Import org.apache.struts.action. *;

Import javax.servlet.http. *;

Import javax.servlet. *;

Import java.io. *;

Import java.util. *;

/ **

* Print field setting back write print.xml file

* /

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

Code

End **************************** /

转载请注明原文地址:https://www.9cbs.com/read-21936.html

New Post(0)