h2.
Introduction
To make the problem a little bit clearer, I will describe the scenario. If
You are only interested at the solution, You can skip this.
We have a non-SAP-Application, that writes a file on the local machine, a xml-file.
After that the user has the opportunity to call a link, which starts a browser
with the URL of a WAS-BSP-Application. We want to make it as easy as possible,
so we give the path and the name of the written file in the URL. So the User
has only to submit the page.
To show how the Applet works I created three bsp-pages:
default.htm - On this page we start the application, on this page you can
find the applet
load.htm - From default.htm we jump on load.htm. We use the Eventhandler
OnInitialization, where we read the file-data (multipart). After that we save
the data in a server side cookie
show.htm - Read the server side cookie, written in load.htm. Display the
data
First of all build a bsp-application, in this example I named it Z_JUPLOAD.
Import the jar-file of the Applet (jupload.jar) that You uploaded from jupload.biz (http://jupload.biz)
as a mime into the new application. Because this weblog is not about authentification
set a default user in transaction SICF for this application.</p>
<p>The layout of default.htm. This page needs a page attribute, name: fileinput,
auto: yes, type: string. With this URL-parameter you can preselect the file.</p>
<p>Sorry but for formatting purposes the following code segments will be contained
only within Textareas:</p>
<p>
<textarea rows="10" cols="79">
<%@page language="abap" %>
<html>
<body>
<table width='550' class="clsTable">
<tr>
<td> </td>
<td>
<applet
code ="JUpload/startup.class"
archive="./jupload.jar"
width ="500"
height ="300"
mayscript
name ="JUpload"
alt ="JUpload by www.jupload.biz">
<!-- Java Plug-In Options -->
<param name="progressbar" value="true">
<param name="boxmessage" value="Loading JUpload Applet ...">
<%-- language dependend Buttons --%>
<param name="labelAdd" value="Add">
<param name="labelRemove" value="Remove">
<param name="labelUpload" value="Upload">
<param name="labelStopUpload" value="Stop Upload">
<%-- Links --%>
<param name="actionURL" value="load.htm">
<param name="completeURL" value="show.htm">
<%-- In this example only one file --%>
<param name="maxNumberFiles" value="1">
<%if not fileinput is initial.%>
<param name="preselectedFiles" value="<%= fileinput%>">
<%endif.%>
<param name="checkResponse" value="true">
<param name="realTimeResponse" value="true">
<!-- IF YOU HAVE PROBLEMS, CHANGE THIS TO TRUE BEFORE CONTACTING SUPPORT -->
<param name="debug" value="false">
Your browser does not support applets. Or you have disabled applet in your options.
To use this applet, please install the newest version of Sun's java. You can get it from java.com (http://www.java.com/)
</applet>
</td>
</tr>
</table>
</body>
</html>
</textarea>
</p>
On this page we need the Eventhandler OnInitialization
event handler for data retrieval
data: i_num type i.
data: i_entity type ref to if_http_entity.
data: i_string type string,
i_uname type string.
data: itab_header_fields type tihttpnvp.
data: i_date type d,
i_time type t.
Get the number of multiparts
call method runtime->server->request->num_multiparts
receiving
num = i_num.
Search in all multiparts for the first file
do i_num times.
call method runtime->server->request->get_multipart
exporting
index = sy-index
receiving
entity = i_entity.
call method i_entity->get_header_fields
changing
fields = itab_header_fields.
read table itab_header_fields with key name = '~content_name'
value = 'uploadedFiles0'
transporting no fields.
if sy-subrc = 0.
This works only, if the file is a textfile
call method i_entity->get_cdata
receiving
data = i_string.
exit.
endif.
enddo.
Save the data in a serverside cookie
i_uname = sy-uname.
i_date = sy-datum + 1.
i_time = sy-uzeit.
call method cl_bsp_server_side_cookie=>set_server_cookie
exporting
name = 'files'
application_name = runtime->application_name
application_namespace = runtime->application_namespace
username = i_uname
session_id = runtime->session_id
data_value = i_string
data_name = 'file1'
expiry_time_abs = i_time
expiry_date_abs = i_date
EXPIRY_TIME_REL =
EXPIRY_DATE_REL =
.
</textarea>
</p>
On this page we read the data from the server side cookie in the Eventhandler
OnInitialization. This page needs one page attribute, name: file1, auto: no,
type: string. We will read the server side cookie into this variable and display
it in the layout.
event handler for data retrieval
data: i_uname type string.
i_uname = sy-uname.
call method cl_bsp_server_side_cookie=>get_server_cookie
exporting
name = 'files'
application_name = runtime->application_name
application_namespace = runtime->application_namespace
username = i_uname
session_id = runtime->session_id
data_name = 'file1'
IMPORTING
EXPIRY_DATE =
EXPIRY_TIME =
changing
data_value = file1
.
</textarea>
</p>
<p>In the Layout we show the file-data. This makes only sense if you downloaded
a textfile.</p>
<p>
<textarea rows="10" cols="79">
<%@page language="abap"%>
<html>
<head>
</head>
<body class="bspBody1">
File:<br>
<%=file1%>
</body>
</html>
</textarea>
</p>
If we both have not done any error, You should get this result: