Skip to main content

Posts

Showing posts with the label HTML

Using HTML5 SessionStorage in forms.

The two local storage mechanisms in HTML5 , 'LocalStorage' and 'SessionStorage' are really nifty when you need to store the data temporarily but don't want to involve any server side interaction. I wanted to create a small HTML-form page which would allow user to enter data in various fields and on submitting the form, just show the data submitted in a text-format (easy for copy-paste). And if needed allow the data to be edited by repopulating the data in the fields. Something like this: On submitting, the entered data shows up like this: On reloading the page, once again we get the first page with data populated in the fields. Pretty cool eh? I decided to use sessionStorage for this. Idea is very simple (and you will notice that implementation is as simple!). Before starting with sessionStorage or JS code, let's take a look at the form HTML code: <form id="bct" > < label>Problem Description/Current Behavior: < /l...

File upload problem: UTF-8 encoding not honored when form has multipart/form-data

The problem that I was facing was something like this. I was using Apache Commons File Upload library to upload and download some file. I had a form in which user can upload a file and another field 'name' in which she can give any name to the file being loaded. When I submitted the form, the file was uploaded fine but the value in name field was garbled. I followed all the possible suggestions I found: <%@page pageEncoding="UTF-8"%> set. < %@page contentType="text/html;charset=UTF-8"% gt; set after the first directive. <meta equiv="Content-Type" content="text/html;charset=UTF-8"> in the head. enctype="multipart/form-data" attribute in the form. accept-charset="UTF-8" attribute in the form. in the Servlet: before doing any operations on request object: request.setCharacterEncoding("UTF-8"); For accessing the value FileItem item = (FileItem) iter.next(); if (item.isFormField()) { //Fo...