Example JSP File
Upload Script

Below
shows a JSP file upload script that is used to print out the
name-value pair received from the earlier XHTML
MP document and save the uploaded file to a certain location on
the WAP server. Remember to change the action
attribute of the <form> element in the earlier XHTML
MP document from
file_upload.php to
file_upload.jsp for
this example to work.

The
following screenshots show what you will see in the Nokia 6230 cell
phone:

Nokia
6230 cell phone

The
above JSP script is very straightforward. Most of the code has been
covered earlier. Below shows some lines of code that you may be
unfamiliar with.

The
line:

<%
response.setContentType("application/vnd.wap.xhtml+xml");
%>

is
used to set the MIME type of the JSP document.
"application/vnd.wap.xhtml+xml" is the MIME type of XHTML
MP.

The
line:

fileName
= FilenameUtils.getName(fileName);

is
used to extract the file name from a path. (FilenameUtils
is a class of the org.apache.commons.io package in the Apache Jakarta Commons IO library.) For
example, both FilenameUtils.getName("/files/myFile.txt")
and FilenameUtils.getName("myFile.txt")
return the string "myFile.txt". The above line of code is
necessary in our JSP script since some browsers provide the full path
of the uploaded file in the HTTP request and so after the execution
of the following line, the fileName
variable may contain a path but not a file name.

String
fileName = fileItem.getName();

As
XHTML MP is compatible with HTML/XHTML, the resulting XHTML MP
document generated by the JSP script can also be viewed on web
browsers such as Microsoft Internet Explorer and Mozilla Firefox.
The only thing you need to do is to remove the following line from
the JSP script:

<%
response.setContentType("application/vnd.wap.xhtml+xml");
%>

This
is because unlike WAP 2.0 browsers on cell phones, Internet Explorer
6 and Mozilla Firefox 2.0 do not understand the MIME type of XHTML
MP. Instead of displaying the XHTML MP document, they will pop up a
dialog box asking you to select a program to open the document or
save the document on disk.

What do you think about this web page? It is very helpful. It is helpful, but some information I wanted is missing. It is not helpful. It has broken links. It has typos / grammatical mistakes. It has incorrect information. Others

(Optional) Please provide us more details. For example, suppose you select option 2 above, can you tell us specifically what information is missing? You can also suggest anything that can help us improve this web page.

(Optional) Your name:

(Optional) Your email address:

Due to the amount of messages we received, we may not be able to reply to all messages.