An Action is an adapter between the contents of an incoming HTTP request and the corresponding business logic that should be executed to process this request. The controller (RequestProcessor) will select an appropriate Action for each request, create an instance (if necessary), and call the execute method.
Actions must be programmed in a thread-safe manner, because the controller will share the same instance for multiple simultaneous requests. This means you should design with the following items in mind:
* Instance and static variables MUST NOT be used to store information related to the state of a particular request. They MAY be used to share global resources across requests for the same action.
* Access to other resources (JavaBeans, session variables, etc.) MUST be synchronized if those resources require protection. (Generally, however, resource classes should be designed to provide their own protection where necessary.
When an Action instance is first created, the controller will call setServlet with a non-null argument to identify the servlet instance to which this Action is attached. When the servlet is to be shut down (or restarted), the setServlet method will be called with a null argument, which can be used to clean up any allocated resources in use by this Action.
Showing posts with label struts Actions. Show all posts
Showing posts with label struts Actions. Show all posts
Tuesday, December 22, 2009
Sunday, September 6, 2009
Struts - DownloadAction
Every struts starter is facing the problem while writing the code for uploading a file. Especially to reduce the burden of writing long code for uploading struts introduced DownloadAction as an added feature from 1.2.6 version onwards. Using this action very easy like eating banana.
i am giving small example on how to use DownloadAction
=======================================================================
public class downloadFileAction extends org.apache.struts.actions.DownloadAction {
protected StreamInfo getStreamInfo(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// File Name
String fileName = "c:\\WriteSelectedRows.pdf";
/*
* To open up in the browser: "inline; filename=myFile.pdf"
* To download: "attachment; filename=myFile.pdf"
* URL for reference: http://wiki.apache.org/struts/StrutsFileDownload
*/
// Set the content disposition
response.setHeader("Content-disposition",
"attachment; filename=" + fileName);
// Download a "pdf" file - gets the file name from the
// Action Mapping's parameter
String contentType = "application/pdf";
File file = new File(fileName);
return new FileStreamInfo(contentType, file);
}
}
=======================================================================
if you want to know more about the Download Action Please go through the URL specified in the above example.
i am giving small example on how to use DownloadAction
=======================================================================
public class downloadFileAction extends org.apache.struts.actions.DownloadAction {
protected StreamInfo getStreamInfo(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// File Name
String fileName = "c:\\WriteSelectedRows.pdf";
/*
* To open up in the browser: "inline; filename=myFile.pdf"
* To download: "attachment; filename=myFile.pdf"
* URL for reference: http://wiki.apache.org/struts/StrutsFileDownload
*/
// Set the content disposition
response.setHeader("Content-disposition",
"attachment; filename=" + fileName);
// Download a "pdf" file - gets the file name from the
// Action Mapping's parameter
String contentType = "application/pdf";
File file = new File(fileName);
return new FileStreamInfo(contentType, file);
}
}
=======================================================================
if you want to know more about the Download Action Please go through the URL specified in the above example.
Subscribe to:
Posts (Atom)