DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Coding
  3. Java
  4. How to upload with Postlet Applet in Java

How to upload with Postlet Applet in Java

A. Programmer user avatar by
A. Programmer
·
May. 04, 11 · Interview
Like (0)
Save
Tweet
Share
5.69K Views

Join the DZone community and get the full member experience.

Join For Free
Postlet is a Java applet used for uploading files to web servers. It supports multiple file uploadusing a nice and easy to use design. Postlet provide 4 main features:

• File progress bar
• Error checking
• Easy selection and upload of multiple files
• Resizing of images over a set size

For a start, you must download Postlet, the Java applet upload, from http://postlet.com/. Extract the postlet.jar under your web application.

The applet is customizable through a set of parameters:

• destination - which is the URL to your servlet that will accept file upload
• language - which is the language to use for Postlet's user interface
• backgroundcolour - which is the color to use for Postlet background
• tableheadercolour - which is the colour to use for the text of the Table Headers
• tableheaderbackgroundcolour - which is the colour to use for the background of the Table Headers
• fileextensions - which is a list of the file extensions
• warnmessage - which is the ability to show a warning message once the upload button is pressed. It’s value can be “true” or “false”
• autoupload - which is the ability to automatically upload files once they are selected. It’s value can be “true” or “false”
• helpbutton - which is the ability to show a help button. It works on versions newer than 0.10.0 and it’s value can be “true” or “false”
• maxpixels - which is the maximum number of pixels allowed for GIF, JPEG and PNG images when there are uploaded. If files exceed this limit, they are resized to the set limit. If are resized GIF images, there are uploaded as PNG images. It works on version newer than 0.13.
• helppage - which is the URL to show if the user clicks the help button. The default URL is to http://www.postlet.com/help/
• maxthreads - which is the maximum number of connections to use. It can takes values from 1 to 5.
• Endpage - which is the URL to take the user to once upload has completed.
• Failedfilesmessage - which is the ability to show the popup message listing the files that failed to upload

A possible configuration is listed below:
<applet name="postlet" code="Main.class" 
archive="./applets/postlet.jar" width="850" height="150" mayscript>
<param name = "maxthreads" value = "5" />
<param name = "language" value = "" />
<param name = "type" value = "application/x-java-applet;version=1.3.1" />
<param name = "destination"
value = "http://localhost:8085/PostletUpload/applet_upload" />
<param name = "backgroundcolour" value = "56328145" />
<param name = "tableheaderbackgroundcolour" value = "24279327" />
<param name = "tableheadercolour" value = "0" />
<param name = "warnmessage" value = "false" />
<param name = "autoupload" value = "false" />
<param name = "helpbutton" value = "false" />
<param name = "fileextensions" value = "Image Files,jpg,gif,jpeg" />
<param name = "endpage" value = "[*** ENDPAGE URL***]" />
<param name = "helppage"
value = "http://www.postlet.com/help/?thisIsTheDefaultAnyway" />
</applet>

When the uploads ends, a JavaScript function can fire up a message:

<script type="text/javascript">
function postletFinished(){
alert("Postlet Applet Succesfully Accomplished its Job!"); }
</script>

For this application (on the server side) you can use the COS described in this post How to upload in Java (Upload using the COS library). Notice the messages returned by the server should by specific to Postlet Upload – http://postlet.com/ you can see the entire list of possible responses. The COS implementation for Postlet Upload is:
public class AppletUploadServlet extends HttpServlet {

protected void processRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {

final int permitedSize = 314572800; //~ 300 MB bytes
final String[] extensions = {".zip",".xls"};

StringBuffer answer = new StringBuffer();
answer.append("POSTLET REPLY\nPOSTLET:YES\nEND POSTLET REPLY\n");

PrintWriter out = response.getWriter();
response.setContentType("text/html;charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "No-cache");
response.setDateHeader("Expires",0);

try{
String strDirectory = "files";
String uploadPath = request.getRealPath("//WEB-INF//"+strDirectory+"//");

//or, like this, from web.xml
String uploadPath_rezerva = request.getRealPath(getServletConfig().
getInitParameter("uploadPath"));

MultipartRequest multipartRequest = new MultipartRequest(request,
uploadPath, permitedSize, "ISO-8859-1", new DefaultFileRenamePolicy());

Enumeration files = multipartRequest.getFileNames();

String extension1 = "";
String extension2 = "";
String filename = "";

while (files.hasMoreElements())
{
String name = (String)files.nextElement();
filename = multipartRequest.getFilesystemName(name);
String originalFilename = multipartRequest.getOriginalFileName(name);

extension1 = filename.substring(filename.length() - 4, filename.length());
extension2 = originalFilename.substring(originalFilename.length() - 4,
originalFilename.length());

//use O'Reilly COS
File currentFile = multipartRequest.getFile(name);
}

out.println(answer);

}catch (Exception exception)
{
answer.delete(0, answer.length());
answer.append("POSTLET REPLY\nPOSTLET:NO\nPOSTLET:SERVER ERROR\n
POSTLET:ABORT ALL\nEND POSTLET REPLY\n");

out.println(answer);
} finally { if(out != null) {out.close();} }
}
}


The result of this application is shown below in figure below:



Download a complete example tested under Tomcat 6 from here.

 

From http://e-blog-java.blogspot.com/2011/03/how-to-upoad-with-postlet-applet-in.html

Upload Java (programming language)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Front-End Troubleshooting Using OpenTelemetry
  • Key Elements of Site Reliability Engineering (SRE)
  • Create Spider Chart With ReactJS
  • DevOps for Developers: Continuous Integration, GitHub Actions, and Sonar Cloud

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: