Monday, 29 April 2013

File Upload Validation on Size or file Extension



Upload only less then 50 kb image size and Allow only jpeg, jpg, gif ,png 
Extensions type.

 <html>
<head>
<script>
function imgdym()
  {
var img = document.getElementById('filename');

var sz =img.files[0].size;
var kbsize = sz/1024
  if(kbsize > 50){ 
alert("Image is Too large! please upload less then 50 kb")
alert("your image size is: "+kbsize+" kb" );

return false;
}
else{
 var img =img.value;
 var arraydata =img.split('.');
 var Extension =arraydata[1];
if ((Extension === 'JPG') || (Extension === 'jpg')|| (Extension === 'jpeg') || (Extension === 'JPEG') || (Extension === 'GIF') || (Extension === 'gif') || (Extension === 'png') || (Extension === 'PNG'))
{
return true;
}
{
alert('Allow only jpeg, jpg, gif ,png');
return false;
}
  } 
}
</script>
</head>
<form action="upload_action.jsp" method="post" enctype="multipart/form-data" name="frmUpload" id="frmUpload">
<table align="center" width="30%" border="1" cellpadding="3" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
<td class="textn"><input type="file" name="filename" id="filename"  accept="image/gif,image/jpeg,image/tiff" class="textbox" ></td>
</tr>
<tr>
<td class="textn">  <input type="submit" name="AddFile" class="textbox1" id="AddFile" onClick="javascript:return imgdym();" value="Update Image"/> <input type="button" name="Cancel" id="Cancel" value="Cancel" class="textbox"/>
</td>
</tr>
</table>
<center><p style="color:#ff3dff;font-size:15px; font-weight:bold;">Upload User Image</p></center>
</form>


Monday, 22 April 2013

Session Tracking Example in jsp



<%@ page import="java.io.*,java.util.*" %>

<%
   // Get session creation time.
   Date createTime = new Date(session.getCreationTime());
   // Get last access time of this web page.
   Date lastAccessTime = new Date(session.getLastAccessedTime());

   String title = "Welcome Back to my website";
   Integer visitCount = new Integer(0);
   String visitCountKey = new String("visitCount");
   String userIDKey = new String("userID");
   String userID = new String("ABCD");

   // Check if this is new comer on your web page.
   if (session.isNew()){
      title = "Welcome to my website";
      session.setAttribute(userIDKey, userID);
      session.setAttribute(visitCountKey,  visitCount);
   } 
   visitCount = (Integer)session.getAttribute(visitCountKey);
 //  out.print(visitCount);
   visitCount = visitCount + 1;
   userID = (String)session.getAttribute(userIDKey);
   session.setAttribute(visitCountKey,  visitCount);
%>
<html>
<head>
<title>Session Tracking</title>
</head>
<body>
<center>
<h2>Session Tracking</h2>
</center>
<table border="1" align="center"> 
<tr bgcolor="#949494">
   <th>Session info</th>
   <th>Value</th>
</tr> 
<tr>
   <td>id</td>
   <td><% out.print( session.getId()); %></td>
</tr> 
<tr>
   <td>Creation Time</td>
   <td><% out.print(createTime); %></td>
</tr> 
<tr>
   <td>Time of Last Access</td>
   <td><% out.print(lastAccessTime); %></td>
</tr> 
<tr>
   <td>User ID</td>
   <td><% out.print(userID); %></td>
</tr> 
<tr>
   <td>Number of visits</td>
   <td><% out.print(visitCount); %></td>
</tr> 
</table> 
</body>
</html>

Friday, 19 April 2013

Add Animated marks to Google Maps in the web page



<head>
<title>Add Animated marker to Google Maps in asp.net website</title>
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
</script>
<script type="text/javascript">
function initialize() {
var myLatlng = new google.maps.LatLng(28.635308000000000000,77.224960000000010000)
var mapOptions = {
center: myLatlng,
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP,
marker: true
};
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
animation:google.maps.Animation.BOUNCE,
title: "New Delhi"
});
marker.setMap(map);
}
</script>
</head>
<body onload="initialize()">
<form id="form1" runat="server">
<div id="map_canvas" style="width: 500px; height: 300px"></div>
</form>
</body>
</html>