Solution
Call the JavaScript function PTC.util.downloadUrl(url) to initiate the file download. See Customization Points for information about the url parameter.
You can call directly from JavaScript, within a <script> section in JSP, or by returning a FormResult from Java with a next action type of FormResultAction.JAVASCRIPT.
Prerequisite Knowledge
To achieve this result, you need to understand:
Basic development of Windchill web pages
JavaScript
Web server configuration and content-disposition
URL security best practices
Solution Elements
Element
Type
Description
main.js
JavaScript
This file includes the JavaScript fragment util.jsf, which defines the PTC.util.downloadUrl(url) function. It is located in //codebase/netmarkets/javascript/util
<MyScript.js> or <MyScriptPart.jsfrag>
JavaScript (whole or fragment)
Code a call to PTC.util.downloadUrl(url) directly in JavaScript or inside a <script> tag in JSP.
<MyPage.jsp> or <MyPagePart.jspf>
JSP (whole or fragment)
<MyWizardFormProcessor.java>
Java class
Use a FormResult object to pass JavaScript to the client for execution. The general pattern is:
formResult.setStatus(FormProcessingStatus.SUCCESS); // or prior value
formResult.setJavascript(js); // where js is a string of JavaScript code
formResult.setNextAction(FormResultAction.JAVASCRIPT); The JavaScript string should include a call to PTC.util.downloadUrl(url); it may also contain other necessary code. If handling the OK button click in a wizard, you should run the download in the opening window:
window.opener.PTC.util.downloadUrl(theURL);
and close the wizard:
window.close();
Procedure – Downloading a Windchill URL
Because PTC.util.downloadURL(url) is a utility function that might be used under many circumstances, no single procedure can anticipate them.
For Javascript and JSP, create or modify the code that needs to initiate the download, calculate or look up the URL of the desired file, and call PTC.util.downloadURL(url) where needed.
For server-side initiation in Java, see Packaged Samples.
URL Security
Your file download implementation must take security issues into account.
Information about the server’s file structure should never be displayed to the user. This includes URLs.
Users should not be allowed to traverse the file structure of the server when downloading a file.
Users should not be allowed to change a parameter, such as filename, when downloading a file.
Users should never be allowed unauthorized access to any file through such traversals or modifications.
Было ли это полезно?